diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-02-28 23:15:58 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-02-28 23:15:58 -0700 |
| commit | 4763fd1a41bc5f6bb59b5c3c079069b84f19305a (patch) | |
| tree | a4f38b1e2150b5d2a88c66d2d96c23b9dd39775c /src/type.zig | |
| parent | 5e2e7675d53c4258a21d014a09f2a6fdae64b433 (diff) | |
| download | zig-4763fd1a41bc5f6bb59b5c3c079069b84f19305a.tar.gz zig-4763fd1a41bc5f6bb59b5c3c079069b84f19305a.zip | |
Sema: clean up peer resolution of errors
* Fix compile error for `zirErrorUnionType`.
* Convert zirMergeErrorSets logic to call `Type.errorSetMerge`.
It does not need to create a Decl as the TODO comment hinted.
* Extract out a function called `resolveInferredErrorSetTy`.
* Rework `resolvePeerTypes` with respect to error unions and
error sets. This is a less complex implementation that passes all the
same tests and uses many fewer lines of code by taking advantage of
the function `coerceInMemoryAllowedErrorSets`.
- Always merge error sets in the order that makes sense, even when
that means `@typeInfo` incompatibility with stage1.
* `Type.errorSetMerge` no longer overallocates.
* Don't skip passing tests.
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/type.zig b/src/type.zig index 34a83999b3..96b8a78dea 100644 --- a/src/type.zig +++ b/src/type.zig @@ -4216,18 +4216,18 @@ pub const Type = extern union { }; } - /// Merge ty with ty2. - /// Asserts that ty and ty2 are both error sets and are resolved. - pub fn errorSetMerge(ty: Type, arena: Allocator, ty2: Type) !Type { - const lhs_names = ty.errorSetNames(); - const rhs_names = ty2.errorSetNames(); - var names = Module.ErrorSet.NameMap{}; - try names.ensureUnusedCapacity(arena, @intCast(u32, lhs_names.len + rhs_names.len)); + /// Merge lhs with rhs. + /// Asserts that lhs and rhs are both error sets and are resolved. + pub fn errorSetMerge(lhs: Type, arena: Allocator, rhs: Type) !Type { + const lhs_names = lhs.errorSetNames(); + const rhs_names = rhs.errorSetNames(); + var names: Module.ErrorSet.NameMap = .{}; + try names.ensureUnusedCapacity(arena, lhs_names.len); for (lhs_names) |name| { names.putAssumeCapacityNoClobber(name, {}); } for (rhs_names) |name| { - names.putAssumeCapacity(name, {}); + try names.put(arena, name, {}); } return try Tag.error_set_merged.create(arena, names); |
