Skip to content

Conversation

@am11
Copy link
Member

@am11 am11 commented Jan 8, 2026

  • Consolidate instruction tokens into main grammar to establish proper lexer precedence over DOTTEDNAME and ID; reorder methodDecl alternatives to match instructions first; add custom attribute handling in method bodies

  • Implement visitor stubs for debug/symbol directives: VisitLanguageDecl, VisitEsHead, VisitExportHead, VisitExtSourceSpec, VisitFieldInit

  • Add typedef resolution in ResolveTypeDef for type aliases

  • Implement label validation: track declared vs referenced labels, report errors for undefined labels at method end

  • Allow recoverable errors in method bodies to still emit assembly

  • Add tests for label validation, typedef resolution, and error handling

- Consolidate instruction tokens into main grammar to establish proper lexer
  precedence over DOTTEDNAME and ID; reorder methodDecl alternatives to
  match instructions first; add custom attribute handling in method bodies

- Implement visitor stubs for debug/symbol directives: VisitLanguageDecl,
  VisitEsHead, VisitExportHead, VisitExtSourceSpec, VisitFieldInit

- Add typedef resolution in ResolveTypeDef for type aliases

- Implement label validation: track declared vs referenced labels, report
  errors for undefined labels at method end

- Allow recoverable errors in method bodies to still emit assembly

- Add tests for label validation, typedef resolution, and error handling
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 8, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 8, 2026
@am11 am11 added area-ILTools-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 8, 2026
@am11 am11 requested a review from jkoritzinsky January 8, 2026 08:07
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT
See info in area-owners.md if you want to be subscribed.

Comment on lines 161 to 169
private static bool IsRecoverableError(string diagnosticId)
{
// Method body diagnostics are recoverable - we emit the assembly but report the error
return diagnosticId is DiagnosticIds.ByteArrayTooShort
or DiagnosticIds.ArgumentNotFound
or DiagnosticIds.LocalNotFound
or DiagnosticIds.LabelNotFound;
}

Copy link
Member

Choose a reason for hiding this comment

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

I think more of these errors might be recoverable, but I'm not 100% positive. Can we compare against ilasm to see what's recoverable there?

For example, I think GenericParameterIndexOutOfRange should be recoverable (the method signature would be invalid, but should still be emittable).

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 have gone through them by comparing native ilasm and fixed them. We may still be missing a few adjustments, but I haven't found much differences. I think once we address all the TODOs in subsequent PRs, we can run the entire native ilasm test suite and to make it a drop-in replacement (+ improvements). We are getting closer. :)


public GrammarResult VisitErrorNode(IErrorNode node) => throw new UnreachableException(NodeShouldNeverBeDirectlyVisited);
public GrammarResult VisitEsHead(CILParser.EsHeadContext context) => throw new NotImplementedException("TODO: Symbols");
public GrammarResult VisitEsHead(CILParser.EsHeadContext context) => GrammarResult.SentinelValue.Result;
Copy link
Member

Choose a reason for hiding this comment

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

Another TODO that hasn't been implemented yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now we have a comment explaining why it's just a pass-thru: // esHead is '.line' or '#line' - this is just the keyword, actual parsing is in VisitExtSourceSpec.

@agocke
Copy link
Member

agocke commented Jan 12, 2026

Can we gather test coverage for ilasm/this change? Test coverage for ilasm should be pretty easy to measure and ideally we would never regress coverage percent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ILTools-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants