Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Jan 28, 2026

  • Move CodeAnnotation out of Function, for easier use.
  • Parse all annotations in one place (parseAnnotations), returning
    a CodeAnnotation. This avoids separate parse this/parse that
    scattered around: all such places now just pass around a
    CodeAnnotation, and they are all applied in one place,
    applyAnnotations.
  • Avoid XPos, XLen pairs in the binary reader: just use a vector of
    lambdas to call, for deferred annotation parsing.

@kripken kripken requested a review from tlively January 28, 2026 21:09
return withLoc(pos,
irBuilder.makeIf(label ? *label : Name{},
type.getSignature(),
parseAnnotations(annotations)));
Copy link
Member

Choose a reason for hiding this comment

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

Should we just pass a CodeAnnotation instead of a const std::vector<Annotation>& into all of these makeXYZ functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly, good question... Looking around a little, that would change hundreds of lines in the parser, so seems like a large refactoring. Perhaps we can consider it after?

makeIf(Name label, Signature sig, std::optional<bool> likely = std::nullopt);
Result<> makeIf(Name label,
Signature sig,
const CodeAnnotation& annotations = CodeAnnotation());
Copy link
Member

Choose a reason for hiding this comment

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

It should be possible to slightly shorten this and reduce duplication:

Suggested change
const CodeAnnotation& annotations = CodeAnnotation());
const CodeAnnotation& annotations = {});

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, done.

@@ -1297,39 +1297,63 @@ struct ParseImplicitTypeDefsCtx : TypeParserCtx<ParseImplicitTypeDefsCtx> {
};

struct AnnotationParserCtx {
Copy link
Member

Choose a reason for hiding this comment

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

Not really related to this change, but it looks like parseAnnotations could just be a free function instead of accessed via multiple inheritance from AnnotationParserCtx.

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems reasonable either way to me, I don't feel strongly.

branchHintsLen = payloadLen;
// Deferred.
deferredAnnotationSections.push_back(
AnnotationSectionInfo{pos, [=, this]() { this->readBranchHints(payloadLen); }});
Copy link
Member

Choose a reason for hiding this comment

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

Listing this shouldn't be necessary, and apparently isn't even valid before C++20? (link)

Suggested change
AnnotationSectionInfo{pos, [=, this]() { this->readBranchHints(payloadLen); }});
AnnotationSectionInfo{pos, [=]() { this->readBranchHints(payloadLen); }});

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, apparently combining = with this is bad... and various fixes hit various warnings, which I found tricky to get passing in both our normal and c++20 testing. The final code seems to work, using

[this, payloadLen]() { this->readBranchHints(payloadLen); }

@tlively
Copy link
Member

tlively commented Jan 28, 2026

Do I understand that this has the (probably inconsequential) side effect of preserving inline hints on Ifs and branch hints on Calls?

@kripken
Copy link
Member Author

kripken commented Jan 29, 2026

Yes, this generalization does mean we handle all hints in more places. As you say it seems inconsequential, and it would add complexity to avoid.

@kripken kripken merged commit 6601663 into WebAssembly:main Jan 29, 2026
17 checks passed
@kripken kripken deleted the pre.callsIfMoved branch January 29, 2026 21:41
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.

2 participants