Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor symbol handling by introducing new name resolution phase #2640

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bterlson
Copy link
Member

@bterlson bterlson commented Nov 7, 2023

This is nowhere near ready, but putting up in draft PR to share progress.

The goals of this change:

  1. Increase performance by doing work early and once and allocating far fewer symbols.
  2. Reduce complexity around binding and resolution by centralizing the logic and cleanly separating symbol resolution from type checking to the extent possible
  3. Fix meta-properties across all use cases we know about
  4. Enable augment decoration of many new things (basically everything we'd want except things involving templates)

Details about the approach can be found in the comment at the top of name-resolver.ts.

Copy link
Contributor

github-actions bot commented Nov 7, 2023

Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status):
Playground: https://cadlplayground.z22.web.core.windows.net/prs/2640/

Website: https://tspwebsitepr.z22.web.core.windows.net/prs/2640/

@bterlson bterlson marked this pull request as draft November 7, 2023 02:14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for testing?

node: TypeReferenceNode | MemberExpressionNode | IdentifierNode,
mapper: TypeMapper | undefined,
instantiateTemplate = true
): { sym: Sym | null; type: Type } {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i never fully get when we should use null, always try to stick to undefined so you don't have to check for multiple things

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to use null for an explicit no thing value since undefined crops up randomly, but do note that much of this code will be completely rewritten once the resolver is operational.

} else if (symbolLinks.declaredType) {
baseType = symbolLinks.declaredType;
} else if (sym.flags & SymbolFlags.Member) {
baseType = checkMemberSym(sym, mapper);
} else {
baseType = checkDeclaredType(sym, decl, mapper);
baseType = getTypeForNode(decl, mapper);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change expected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the checker changes were from when I thought I could fix everything without refactoring how symbols work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah make sense

@@ -1177,6 +1250,9 @@ export function createChecker(program: Program): Checker {
parentMapper: TypeMapper | undefined,
instantiateTempalates = true
): Type {
if (templateNode.id.sv === "bar") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover debugger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants