plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
b7a7ea1
— Peter John
2026-11-10T21:18:13+05:30
Codegen: an in-place spread compares whole types for a bare named source too
compiler/wasm-codegen/src/units.rs
CHANGED
|
@@ -176,9 +176,10 @@ pub(crate) fn spreadInPlace(
|
|
|
176
176
|
// arguments has one struct, so a spread that keeps them writes the cell it read; one
|
|
177
177
|
// that changes them (`Box(..b, value: f(b.value))` from a `Box<A>` to a `Box<B>`)
|
|
178
178
|
// builds another struct and copies. `result` is the spread's own type.
|
|
179
|
+
// Compared as whole types whichever form the source's type arrives in: a bare
|
|
180
|
+
// `TNamed` source with a generic result must not pass on the name alone.
|
|
179
181
|
match inferLocalType(sp, ctx) {
|
|
180
|
-
PlumType::TNamed(ref n) if *n == call.type_name => {}
|
|
181
|
-
ref src @ PlumType::TApp(ref n, _) if *n == call.type_name && canonTy(src) == canonTy(result) => {}
|
|
182
|
+
ref src @ (PlumType::TNamed(ref n) | PlumType::TApp(ref n, _)) if *n == call.type_name && canonTy(src) == canonTy(result) => {}
|
|
182
183
|
_ => return false,
|
|
183
184
|
}
|
|
184
185
|
!plum_core::uniqueness::inPlaceHazard(name, &call.fields)
|
tests/fbip/generic_types.plum
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# changes the type arguments builds another struct, and a value someone else still holds is
|
|
4
4
|
# copied: the results are the same with and without `--no-fbip`.
|
|
5
5
|
import std/Int
|
|
6
|
+
import std/Float
|
|
6
7
|
import std/Str
|
|
7
8
|
import std/collections/List
|
|
8
9
|
|
|
@@ -59,3 +60,14 @@ test "two type parameters, a nested generic field and a list of them"
|
|
|
59
60
|
ys := bumpAll(xs)
|
|
60
61
|
assert ys.at(1).n == 11
|
|
61
62
|
assert xs.at(1).n == 10
|
|
63
|
+
|
|
64
|
+
test "a chain of spreads that each change the type arguments"
|
|
65
|
+
# each step's source is used once, so each is a candidate for an in-place write: only
|
|
66
|
+
# the bump keeps the type, and only it may write the cell it read
|
|
67
|
+
b := Box(value: 5, n: 1).with(2.5).bump().with("q").with(Box(value: 1, n: 0)).bump().with(8)
|
|
68
|
+
assert b.value == 8
|
|
69
|
+
assert b.n == 3
|
|
70
|
+
p := Pair2(a: 9, b: "s", hits: 4).hit()
|
|
71
|
+
q: Pair2<Str, Str> := Pair2(..p, a: "a{p.a}")
|
|
72
|
+
assert q.a == "a9"
|
|
73
|
+
assert q.hits == 5
|