plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


40e4292 — Peter John 2026-11-10T20:04:23+05:30
Checker: open-dispatch instantiations in a fixed order
compiler/checker/src/callsites.rs CHANGED
@@ -149,6 +149,10 @@ pub(crate) fn recordOpenDispatches(info: &TypedInfo) -> bool {
149
149
  info.inst_expr_types.values().chain(info.inst_annotated.values()).for_each(&mut add);
150
150
  info.instantiations.iter().flat_map(|i| i.type_args.iter()).for_each(&mut add);
151
151
  });
152
+ // In a fixed order: the sites become instantiations, whose order is the order of the
153
+ // errors and of the emitted functions.
154
+ let mut instances: Vec<PlumType> = instances.into_iter().collect();
155
+ instances.sort_by_cached_key(|t| t.to_string());
152
156
  let traits = currentTraits();
153
157
  let mut sites: Vec<CallSite> = Vec::new();
154
158
  for o in &open {
compiler/checker/tests/checker/review_tests.rs CHANGED
@@ -145,3 +145,20 @@ fn a_parse_time_form_error_names_its_own_file() {
145
145
  assert!(e.file.ends_with("m.plum"), "{e:?}");
146
146
  assert_eq!(e.line, 4, "{e:?}");
147
147
  }
148
+
149
+ /// The methods compiled for each `Box<..>` a trait-object call may reach come out in one
150
+ /// order on every compile (they were taken from a `HashSet`).
151
+ #[test]
152
+ fn open_dispatch_instantiations_come_out_in_a_fixed_order() {
153
+ let src = "import std/Int\nimport std/Str\nimport std/Float\nimport std/Bool\n\n\
154
+ trait Thing<M> =\n fun key(self) -> Int\n\n\
155
+ trait Sized =\n fun size(self) -> Int\n\n\
156
+ struct Box<M>[Thing<M>, Sized](id: Int, w: Int) =\n fun key(self) -> Int = self.id\n fun size(self) -> Int = self.w * 10\n\n\
157
+ fun sizeOf<M>(t: Thing<M>) -> Int = match t\n Sized as s => s.size()\n _ => -1\n\n\
158
+ fun main() -> Int =\n a: Thing<Int> := Box(id: 1, w: 2)\n b: Thing<Str> := Box(id: 2, w: 5)\n c: Thing<Float> := Box(id: 3, w: 1)\n d: Thing<Bool> := Box(id: 4, w: 7)\n sizeOf(a) + sizeOf(b) + sizeOf(c) + sizeOf(d)\n";
159
+ let first = plum_test_support::compile("open_order", src);
160
+ for _ in 0..6 {
161
+ assert!(plum_test_support::compile("open_order", src) == first, "the wasm differs between compiles");
162
+ }
163
+ assert_eq!(plum_test_support::runInt("open_order", src), 150);
164
+ }