-
Notifications
You must be signed in to change notification settings - Fork 699
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
Fix parsing for typed function reference types #1889
Open
takikawa
wants to merge
2
commits into
WebAssembly:main
Choose a base branch
from
takikawa:fix-typed-funcref-crash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -853,7 +853,7 @@ bool WastParser::ParseElemExprVarListOpt(ExprListVector* out_list) { | |
return !out_list->empty(); | ||
} | ||
|
||
Result WastParser::ParseValueType(Var* out_type) { | ||
Result WastParser::ParseValueType(Type* out_type, Var* out_var) { | ||
WABT_TRACE(ParseValueType); | ||
|
||
const bool is_ref_type = PeekMatchRefType(); | ||
|
@@ -866,8 +866,17 @@ Result WastParser::ParseValueType(Var* out_type) { | |
if (is_ref_type) { | ||
EXPECT(Lpar); | ||
EXPECT(Ref); | ||
CHECK_RESULT(ParseVar(out_type)); | ||
Var name; | ||
CHECK_RESULT(ParseVar(&name)); | ||
if (out_var) { | ||
*out_var = name; | ||
} | ||
EXPECT(Rpar); | ||
if (name.is_index()) { | ||
*out_type = Type(Type::Reference, name.index()); | ||
} else { | ||
*out_type = Type(Type::Reference, kInvalidIndex); | ||
} | ||
return Result::Ok; | ||
} | ||
|
||
|
@@ -892,7 +901,7 @@ Result WastParser::ParseValueType(Var* out_type) { | |
return Result::Error; | ||
} | ||
|
||
*out_type = Var(type); | ||
*out_type = type; | ||
return Result::Ok; | ||
} | ||
|
||
|
@@ -905,17 +914,15 @@ Result WastParser::ParseValueTypeList( | |
break; | ||
} | ||
|
||
Var type; | ||
CHECK_RESULT(ParseValueType(&type)); | ||
Var index; | ||
Type type; | ||
CHECK_RESULT(ParseValueType(&type, &index)); | ||
|
||
if (type.is_index()) { | ||
out_type_list->push_back(Type(type.index())); | ||
} else { | ||
assert(type.is_name()); | ||
if (index.is_name()) { | ||
assert(options_->features.function_references_enabled()); | ||
type_names->emplace(out_type_list->size(), type.name()); | ||
out_type_list->push_back(Type(Type::Reference, kInvalidIndex)); | ||
type_names->emplace(out_type_list->size(), index.name()); | ||
} | ||
out_type_list->push_back(type); | ||
} | ||
|
||
return Result::Ok; | ||
|
@@ -1427,15 +1434,11 @@ Result WastParser::ParseField(Field* field) { | |
// TODO: Share with ParseGlobalType? | ||
if (MatchLpar(TokenType::Mut)) { | ||
field->mutable_ = true; | ||
Var type; | ||
CHECK_RESULT(ParseValueType(&type)); | ||
field->type = Type(type.index()); | ||
CHECK_RESULT(ParseValueType(&field->type)); | ||
EXPECT(Rpar); | ||
} else { | ||
field->mutable_ = false; | ||
Var type; | ||
CHECK_RESULT(ParseValueType(&type)); | ||
field->type = Type(type.index()); | ||
CHECK_RESULT(ParseValueType(&field->type)); | ||
} | ||
return Result::Ok; | ||
}; | ||
|
@@ -1793,20 +1796,18 @@ Result WastParser::ParseBoundValueTypeList( | |
while (MatchLpar(token)) { | ||
if (PeekMatch(TokenType::Var)) { | ||
std::string name; | ||
Var type; | ||
Var index; | ||
Type type; | ||
Location loc = GetLocation(); | ||
ParseBindVarOpt(&name); | ||
CHECK_RESULT(ParseValueType(&type)); | ||
CHECK_RESULT(ParseValueType(&type, &index)); | ||
bindings->emplace(name, | ||
Binding(loc, binding_index_offset + types->size())); | ||
if (type.is_index()) { | ||
types->push_back(Type(type.index())); | ||
} else { | ||
assert(type.is_name()); | ||
if (index.is_name()) { | ||
assert(options_->features.function_references_enabled()); | ||
type_names->emplace(binding_index_offset + types->size(), type.name()); | ||
types->push_back(Type(Type::Reference, kInvalidIndex)); | ||
type_names->emplace(binding_index_offset + types->size(), index.name()); | ||
} | ||
types->push_back(type); | ||
} else { | ||
CHECK_RESULT(ParseValueTypeList(types, type_names)); | ||
} | ||
|
@@ -3116,15 +3117,11 @@ Result WastParser::ParseGlobalType(Global* global) { | |
WABT_TRACE(ParseGlobalType); | ||
if (MatchLpar(TokenType::Mut)) { | ||
global->mutable_ = true; | ||
Var type; | ||
CHECK_RESULT(ParseValueType(&type)); | ||
global->type = Type(type.index()); | ||
CHECK_RESULT(ParseValueType(&global->type)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the simplification we get from have ParseValueType return the Type directly. |
||
CHECK_RESULT(ErrorIfLpar({"i32", "i64", "f32", "f64"})); | ||
EXPECT(Rpar); | ||
} else { | ||
Var type; | ||
CHECK_RESULT(ParseValueType(&type)); | ||
global->type = Type(type.index()); | ||
CHECK_RESULT(ParseValueType(&global->type)); | ||
} | ||
|
||
return Result::Ok; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
;;; TOOL: wat2wasm | ||
;;; ARGS: --enable-function-references | ||
(module | ||
(type $f32-f32-1 (func (param f32) (result f32))) | ||
(type $f32-f32-2 (func (param f32) (result f32))) | ||
|
||
(func $foo (param $f (ref $f32-f32-1)) (result f32) | ||
(call_ref (f32.const 42.0) (local.get $f)) | ||
) | ||
|
||
(func $bar (type $f32-f32-2) | ||
(f32.const 1.0) | ||
) | ||
|
||
(func (export "main") (result f32) | ||
;; $f32-f32-1 and $f32-f32-2 should be equal | ||
(call $foo (ref.func $bar)) | ||
) | ||
|
||
(elem declare funcref (ref.func $bar)) | ||
) | ||
|
||
(;; STDERR ;;; | ||
;;; STDERR ;;) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be an error?