diff options
author | Thomas Lively <tlively@google.com> | 2024-04-19 17:07:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-19 17:07:43 -0700 |
commit | 219e668e87b012c0634043ed702534b8be31231f (patch) | |
tree | d482fb6ccbc165ea6709845d70f7d712672886f3 /src | |
parent | c60fe154ac09deb9227165d388c5f950bab6e052 (diff) | |
download | binaryen-219e668e87b012c0634043ed702534b8be31231f.tar.gz binaryen-219e668e87b012c0634043ed702534b8be31231f.tar.bz2 binaryen-219e668e87b012c0634043ed702534b8be31231f.zip |
[Parser][NFC] Do less work when parsing function types (#6516)
After the initial parsing pass to find the locations of all the module elements
and after the type definitions have been parsed, the next phase of parsing is to
visit all of the module elements and parse their types. This phase does not
require parsing function bodies, but it previously parsed entire functions
anyway for simplicity. To improve performance, skip that useless work.
Diffstat (limited to 'src')
-rw-r--r-- | src/parser/contexts.h | 6 | ||||
-rw-r--r-- | src/parser/parsers.h | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h index d68d475a0..81537abaf 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -173,6 +173,8 @@ struct NullTypeParserCtx { BlockTypeT getBlockTypeFromResult(size_t results) { return Ok{}; } Result<> getBlockTypeFromTypeUse(Index, TypeUseT) { return Ok{}; } + + bool skipFunctionBody() { return false; } }; template<typename Ctx> struct TypeParserCtx { @@ -310,6 +312,8 @@ template<typename Ctx> struct TypeParserCtx { assert(results.size() == 1); return HeapType(Signature(Type::none, results[0])); } + + bool skipFunctionBody() { return false; } }; struct NullInstrParserCtx { @@ -1198,6 +1202,8 @@ struct ParseModuleTypesCtx : TypeParserCtx<ParseModuleTypesCtx>, types(types), implicitTypes(implicitTypes), implicitElemIndices(implicitElemIndices) {} + bool skipFunctionBody() { return true; } + Result<HeapTypeT> getHeapTypeFromIdx(Index idx) { if (idx >= types.size()) { return in.err("type index out of bounds"); diff --git a/src/parser/parsers.h b/src/parser/parsers.h index bbb50b664..25078f354 100644 --- a/src/parser/parsers.h +++ b/src/parser/parsers.h @@ -3028,11 +3028,13 @@ template<typename Ctx> MaybeResult<> func(Ctx& ctx) { CHECK_ERR(l); localVars = *l; } - CHECK_ERR(instrs(ctx)); - ctx.setSrcLoc(ctx.in.takeAnnotations()); + if (!ctx.skipFunctionBody()) { + CHECK_ERR(instrs(ctx)); + ctx.setSrcLoc(ctx.in.takeAnnotations()); + } } - if (!ctx.in.takeRParen()) { + if (!ctx.skipFunctionBody() && !ctx.in.takeRParen()) { return ctx.in.err("expected end of function"); } |