Skip to content

Commit

Permalink
Merge pull request #1999 from tokiwa-software/remove_Any_hash_code
Browse files Browse the repository at this point in the history
lib: Remove Any.hash_code
  • Loading branch information
michaellilltokiwa authored Sep 20, 2023
2 parents 6204194 + b896b06 commit e356626
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 14 deletions.
1 change: 0 additions & 1 deletion lib/Any.fz
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#
public Any ref is

public hash_code i32 is intrinsic

# create a String from this instance. Unless redefined, `a.as_string` will
# create `"instance[T]"` where `T` is the dynamic type of `a`
Expand Down
8 changes: 0 additions & 8 deletions src/dev/flang/be/c/Intrinsics.java
Original file line number Diff line number Diff line change
Expand Up @@ -766,14 +766,6 @@ else if (c._fuir.clazzIsRef(rc) ||
put("f32.type.tanh" , (c,cl,outer,in) -> CExpr.call("tanhf", new List<>(A0)).ret());
put("f64.type.tanh" , (c,cl,outer,in) -> CExpr.call("tanh", new List<>(A0)).ret());

put("Any.hash_code" , (c,cl,outer,in) ->
{
var or = c._fuir.clazzOuterRef(cl);
var hc = c._fuir.clazzIsRef(c._fuir.clazzResultClazz(or))
? CNames.OUTER.castTo("char *").sub(new CIdent("NULL").castTo("char *")).castTo("int32_t") // NYI: This implementation of hash_code relies on non-compacting GC
: CExpr.int32const(42); // NYI: This implementation of hash_code is stupid
return hc.ret();
});
put("Any.as_string" , (c,cl,outer,in) ->
{
var res = new CIdent("res");
Expand Down
1 change: 0 additions & 1 deletion src/dev/flang/be/interpreter/Intrinsics.java
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,6 @@ else if (desc instanceof ByteChannel sc)
put("f64.type.square_root" , (interpreter, innerClazz) -> args -> new f64Value ( Math.sqrt( args.get(1).f64Value())));
put("f64.type.tan" , (interpreter, innerClazz) -> args -> new f64Value ( Math.tan( args.get(1).f64Value())));
put("f64.type.tanh" , (interpreter, innerClazz) -> args -> new f64Value ( Math.tanh( args.get(1).f64Value())));
put("Any.hash_code" , (interpreter, innerClazz) -> args -> new i32Value (args.get(0).toString().hashCode()));
put("Any.as_string" , (interpreter, innerClazz) -> args -> Interpreter.value("instance[" + innerClazz._outer.toString() + "]"));
put("fuzion.std.nano_time" , (interpreter, innerClazz) -> args -> new u64Value (System.nanoTime()));
put("fuzion.std.nano_sleep" , (interpreter, innerClazz) -> args ->
Expand Down
3 changes: 1 addition & 2 deletions src/dev/flang/be/jvm/Intrinsix.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ else if (in.equals("fuzion.sys.internal_array.setel"))
});

put(new String[]
{ "Any.hash_code",
"concur.atomic.compare_and_set0",
{ "concur.atomic.compare_and_set0",
"concur.atomic.compare_and_swap0",
"concur.atomic.read0",
"concur.atomic.write0",
Expand Down
1 change: 0 additions & 1 deletion src/dev/flang/fuir/analysis/dfa/DFA.java
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,6 @@ void tempEscapes(int cl, int c, int i, Val v, int adrField)
put("f32.type.tanh" , cl -> new NumericValue(cl._dfa, cl._dfa._fuir.clazzResultClazz(cl._cc)) );
put("f64.type.tanh" , cl -> new NumericValue(cl._dfa, cl._dfa._fuir.clazzResultClazz(cl._cc)) );

put("Any.hash_code" , cl -> new NumericValue(cl._dfa, cl._dfa._fuir.clazzResultClazz(cl._cc)) );
put("Any.as_string" , cl -> cl._dfa.newConstString(null, cl) );
put("fuzion.sys.internal_array_init.alloc", cl -> { return new SysArray(cl._dfa, new byte[0]); } ); // NYI: get length from args
put("fuzion.sys.internal_array.setel", cl ->
Expand Down
1 change: 0 additions & 1 deletion src/dev/flang/fuir/cfg/CFG.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ void createCallGraphForIntrinsic(int cl)
put("f32.type.tanh" , (cfg, cl) -> { } );
put("f64.type.tanh" , (cfg, cl) -> { } );

put("Any.hash_code" , (cfg, cl) -> { } );
put("Any.as_string" , (cfg, cl) -> { } );
put("fuzion.sys.internal_array_init.alloc", (cfg, cl) -> { } );
put("fuzion.sys.internal_array.setel", (cfg, cl) -> { } );
Expand Down
8 changes: 8 additions & 0 deletions tests/functions/functions.fz
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@

functions is

# this test uses Any.hash_code, which no longer exists. So we provide it here:
Any.hash_code =>
for
r := 4711, r *° 257 +° c.as_i32
c in Any.this.as_string.utf8
else
r

y(f ()->i32){}
x0(f0 Function i32 Any i32) is
say "here 1x0---------------"
Expand Down

0 comments on commit e356626

Please sign in to comment.