Address Spaces: basic system to check for validity.

Validity checks are also based on context; whether the entity being validated
is a mutable/constant value, a pointer (that is ascripted with an addrspace
attribute) or a function with an addrspace attribute. Error messages are
relatively simple for now.
This commit is contained in:
Robin Voetter
2021-09-01 17:33:45 +02:00
parent 90a945b38c
commit 13b917148e
2 changed files with 68 additions and 8 deletions

View File

@@ -3213,11 +3213,18 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
break :blk (try sema.resolveInstConst(&block_scope, src, linksection_ref)).val;
};
const address_space = blk: {
const addrspace_ref = decl.zirAddrspaceRef();
if (addrspace_ref == .none) break :blk .generic;
const addrspace_tv = try sema.resolveInstConst(&block_scope, src, addrspace_ref);
break :blk addrspace_tv.val.toEnum(std.builtin.AddressSpace);
const addrspace_ctx: Sema.AddressSpaceContext = switch (decl_tv.val.tag()) {
.function, .extern_fn => .function,
.variable => .variable,
else => .constant,
};
break :blk switch (decl.zirAddrspaceRef()) {
.none => .generic,
else => |addrspace_ref| try sema.analyzeAddrspace(&block_scope, src, addrspace_ref, addrspace_ctx),
};
};
// Note this resolves the type of the Decl, not the value; if this Decl
// is a struct, for example, this resolves `type` (which needs no resolution),
// not the struct itself.