Skip to content

Type Equality/Compatibility Revamp #286

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

Merged
merged 8 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions RELEASENOTES.docu
Original file line number Diff line number Diff line change
Expand Up @@ -1784,4 +1784,12 @@ extern typedef struct { } my_type_t;</pre> </add-note></build-id>
attribute values <bug number="SIMICS-22406"/>.
<tt>legacy_attributes</tt> will always be disabled with Simics API version
8 or above.</add-note></build-id>
<build-id _6="next" _7="next"><add-note>Typechecking has been reworked
to be more strict, and more accurately reject type mismatch that would
result in invalid C or GCC warnings <bug number="SIMICS-9504"/>. To
avoid breakage from novel type errors from the stricter typechecking,
which particularly affects pointer types, the legacy lenient typechecking
is still used by default with Simics API version 7 or below. The strict
typechecking can be enabled by passing
<tt>--no-compat=lenient_typechecking</tt> to DMLC.</add-note></build-id>
</rn>
1 change: 1 addition & 0 deletions lib/1.2/dml-builtins.dml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ template device {
parameter _compat_shared_logs_on_device auto;
parameter _compat_suppress_WLOGMIXUP auto;
parameter _compat_legacy_attributes auto;
parameter _compat_lenient_typechecking auto;
parameter _compat_dml12_inline auto;
parameter _compat_dml12_not auto;
parameter _compat_dml12_goto auto;
Expand Down
32 changes: 16 additions & 16 deletions lib/1.2/simics-api.dml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ extern uint16 CONVERT_BE16(uint16 val);
extern uint32 CONVERT_BE32(uint32 val);
extern uint64 CONVERT_BE64(uint64 val);

extern uint8 LOAD_LE8 (void *src);
extern uint16 LOAD_LE16(void *src);
extern uint32 LOAD_LE32(void *src);
extern uint64 LOAD_LE64(void *src);
extern uint8 LOAD_LE8 (const void *src);
extern uint16 LOAD_LE16(const void *src);
extern uint32 LOAD_LE32(const void *src);
extern uint64 LOAD_LE64(const void *src);

extern uint8 LOAD_BE8 (void *src);
extern uint16 LOAD_BE16(void *src);
extern uint32 LOAD_BE32(void *src);
extern uint64 LOAD_BE64(void *src);
extern uint8 LOAD_BE8 (const void *src);
extern uint16 LOAD_BE16(const void *src);
extern uint32 LOAD_BE32(const void *src);
extern uint64 LOAD_BE64(const void *src);

extern void STORE_LE8 (void *dst, uint8 val);
extern void STORE_LE16(void *dst, uint16 val);
Expand All @@ -68,15 +68,15 @@ extern void STORE_BE16(void *dst, uint16 val);
extern void STORE_BE32(void *dst, uint32 val);
extern void STORE_BE64(void *dst, uint64 val);

extern uint8 UNALIGNED_LOAD_LE8 (void *src);
extern uint16 UNALIGNED_LOAD_LE16(void *src);
extern uint32 UNALIGNED_LOAD_LE32(void *src);
extern uint64 UNALIGNED_LOAD_LE64(void *src);
extern uint8 UNALIGNED_LOAD_LE8 (const void *src);
extern uint16 UNALIGNED_LOAD_LE16(const void *src);
extern uint32 UNALIGNED_LOAD_LE32(const void *src);
extern uint64 UNALIGNED_LOAD_LE64(const void *src);

extern uint8 UNALIGNED_LOAD_BE8 (void *src);
extern uint16 UNALIGNED_LOAD_BE16(void *src);
extern uint32 UNALIGNED_LOAD_BE32(void *src);
extern uint64 UNALIGNED_LOAD_BE64(void *src);
extern uint8 UNALIGNED_LOAD_BE8 (const void *src);
extern uint16 UNALIGNED_LOAD_BE16(const void *src);
extern uint32 UNALIGNED_LOAD_BE32(const void *src);
extern uint64 UNALIGNED_LOAD_BE64(const void *src);

extern void UNALIGNED_STORE_LE8 (void *dst, uint8 val);
extern void UNALIGNED_STORE_LE16(void *dst, uint16 val);
Expand Down
1 change: 1 addition & 0 deletions lib/1.4/dml-builtins.dml
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ template device {
param _compat_shared_logs_on_device auto;
param _compat_suppress_WLOGMIXUP auto;
param _compat_legacy_attributes auto;
param _compat_lenient_typechecking auto;
param _compat_dml12_inline auto;
param _compat_dml12_not auto;
param _compat_dml12_goto auto;
Expand Down
32 changes: 16 additions & 16 deletions lib/1.4/internal.dml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ extern uint16 CONVERT_BE16(uint16 val);
extern uint32 CONVERT_BE32(uint32 val);
extern uint64 CONVERT_BE64(uint64 val);

extern uint8 LOAD_LE8 (void *src);
extern uint16 LOAD_LE16(void *src);
extern uint32 LOAD_LE32(void *src);
extern uint64 LOAD_LE64(void *src);
extern uint8 LOAD_LE8 (const void *src);
extern uint16 LOAD_LE16(const void *src);
extern uint32 LOAD_LE32(const void *src);
extern uint64 LOAD_LE64(const void *src);

extern uint8 LOAD_BE8 (void *src);
extern uint16 LOAD_BE16(void *src);
extern uint32 LOAD_BE32(void *src);
extern uint64 LOAD_BE64(void *src);
extern uint8 LOAD_BE8 (const void *src);
extern uint16 LOAD_BE16(const void *src);
extern uint32 LOAD_BE32(const void *src);
extern uint64 LOAD_BE64(const void *src);

extern void STORE_LE8 (void *dst, uint8 val);
extern void STORE_LE16(void *dst, uint16 val);
Expand All @@ -59,15 +59,15 @@ extern void STORE_BE16(void *dst, uint16 val);
extern void STORE_BE32(void *dst, uint32 val);
extern void STORE_BE64(void *dst, uint64 val);

extern uint8 UNALIGNED_LOAD_LE8 (void *src);
extern uint16 UNALIGNED_LOAD_LE16(void *src);
extern uint32 UNALIGNED_LOAD_LE32(void *src);
extern uint64 UNALIGNED_LOAD_LE64(void *src);
extern uint8 UNALIGNED_LOAD_LE8 (const void *src);
extern uint16 UNALIGNED_LOAD_LE16(const void *src);
extern uint32 UNALIGNED_LOAD_LE32(const void *src);
extern uint64 UNALIGNED_LOAD_LE64(const void *src);

extern uint8 UNALIGNED_LOAD_BE8 (void *src);
extern uint16 UNALIGNED_LOAD_BE16(void *src);
extern uint32 UNALIGNED_LOAD_BE32(void *src);
extern uint64 UNALIGNED_LOAD_BE64(void *src);
extern uint8 UNALIGNED_LOAD_BE8 (const void *src);
extern uint16 UNALIGNED_LOAD_BE16(const void *src);
extern uint32 UNALIGNED_LOAD_BE32(const void *src);
extern uint64 UNALIGNED_LOAD_BE64(const void *src);

extern void UNALIGNED_STORE_LE8 (void *dst, uint8 val);
extern void UNALIGNED_STORE_LE16(void *dst, uint16 val);
Expand Down
6 changes: 3 additions & 3 deletions py/dml/c_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,13 +805,13 @@ def generate_implement_method(device, ifacestruct, meth, indices):
# method in DML
raise EMETH(meth.site, None, 'interface method is variadic')
for ((mp, mt), it) in zip(meth.inp, iface_input_types):
if safe_realtype(mt).cmp(safe_realtype(it)) != 0:
if not safe_realtype_unconst(mt).eq(safe_realtype_unconst(it)):
raise EARGT(meth.site, 'implement', meth.name,
mt, mp, it, 'method')
if iface_num_outputs and dml.globals.dml_version != (1, 2):
[(_, mt)] = meth.outp
if safe_realtype(mt).cmp(
safe_realtype(func_type.output_type)) != 0:
if not safe_realtype_unconst(mt).eq(
safe_realtype_unconst(func_type.output_type)):
raise EARGT(meth.site, 'implement', meth.name,
mt, '<return value>', func_type.output_type,
'method')
Expand Down
45 changes: 0 additions & 45 deletions py/dml/clone_test.py

This file was deleted.

20 changes: 4 additions & 16 deletions py/dml/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,18 +1306,7 @@ def expr_cast(tree, location, scope):
for (site, _) in struct_defs:
report(EANONSTRUCT(site, "'cast' expression"))

if (compat.dml12_misc in dml.globals.enabled_compat
and isinstance(expr, InterfaceMethodRef)):
# Workaround for SIMICS-9868
return mkLit(tree.site, "%s->%s" % (
expr.node_expr.read(), expr.method_name), type)

if isinstance(expr, NonValue) and (
not isinstance(expr, NodeRef)
or not isinstance(safe_realtype(type), TTrait)):
raise expr.exc()
else:
return mkCast(tree.site, expr, type)
return mkCast(tree.site, expr, type)

@expression_dispatcher
def expr_undefined(tree, location, scope):
Expand Down Expand Up @@ -1518,7 +1507,7 @@ def eval_type(asttype, site, location, scope, extern=False, typename=None,
raise EBFLD(fsite, "field %s has wrong size" % name)

members[name] = (mtype, msb, lsb)
etype = TInt(width, False, members)
etype = TInt(width, False, members, label=typename)
elif tag == 'typeof':
expr = codegen_expression_maybe_nonvalue(info, location, scope)
if isinstance(expr, NonValue):
Expand Down Expand Up @@ -2008,9 +1997,8 @@ def mk_sym(name, typ, mkunique=not dml.globals.debuggable):
for (name, typ) in decls:
sym = mk_sym(name, typ)
tgt_typ = safe_realtype_shallow(typ)
if tgt_typ.const:
nonconst_typ = tgt_typ.clone()
nonconst_typ.const = False
if shallow_const(tgt_typ):
nonconst_typ = safe_realtype_unconst(tgt_typ)
tgt_sym = mk_sym('_tmp_' + name, nonconst_typ, True)
sym.init = ExpressionInitializer(mkLocalVariable(stmt.site,
tgt_sym))
Expand Down
23 changes: 23 additions & 0 deletions py/dml/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,29 @@ class legacy_attributes(CompatFeature):
+ "dictionary type ('D')")
last_api_version = api_7

@feature
class lenient_typechecking(CompatFeature):
'''This compatibility feature makes DMLC's type checking very inexact and
lenient in multiple respects when compared to GCC's type checking of the
generated C.
This discrepency mostly affects method overrides or uses of `extern`:d C
macros, because in those scenarios DMLC can become wholly responsible for
proper type checking.

While migrating away from this feature, the most common type errors that
its disablement introduces are due to discrepencies between pointer
types. In particular, implicitly discarding `const`-qualification of a
pointer's base type will never be tolerated, and `void` pointers are only
considered equivalent with any other pointer type in the same contexts as
C.

Novel type errors from uses of `extern`:d macros can often be resolved by
changing the signature of the `extern` declaration to more accurately
reflect the macro's effective type.
'''
short = "Make type checking inexact and lenient"
last_api_version = api_7

@feature
class dml12_inline(CompatFeature):
'''When using `inline` to inline a method in a DML 1.2 device,
Expand Down
Loading