Skip to content

Commit 306f36d

Browse files
authored
Merge pull request #182 from nikhilc1527/new
translation bug for ref into slice
2 parents 491503f + 19cabdf commit 306f36d

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

goose.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,6 @@ func (ctx *Ctx) unaryExpr(e *ast.UnaryExpr, multipleBindings bool) glang.Expr {
717717
return glang.NotExpr{X: ctx.expr(e.X)}
718718
}
719719
if e.Op == token.AND {
720-
if x, ok := e.X.(*ast.IndexExpr); ok {
721-
// e is &a[b] where x is a.b
722-
return glang.NewCallExpr(glang.VerbatimExpr("IndexRef"),
723-
ctx.glangType(e, ctx.typeOf(x)),
724-
glang.TupleExpr{ctx.expr(x.X), ctx.expr(x.Index)})
725-
}
726720
if cl, ok := e.X.(*ast.CompositeLit); ok {
727721
// e is &T{...} (a composite literal)
728722
sl := ctx.compositeLiteral(cl)

testdata/examples/semantics/generated_test.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testdata/examples/semantics/semantics.gold.v

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ Definition testSliceLiteral {ext : ffi_syntax} {go_gctx : GoGlobalContext} : go_
411411

412412
Definition testSliceAppend {ext : ffi_syntax} {go_gctx : GoGlobalContext} : go_string := "github.com/goose-lang/goose/testdata/examples/semantics.testSliceAppend"%go.
413413

414+
Definition testSliceRef {ext : ffi_syntax} {go_gctx : GoGlobalContext} : go_string := "github.com/goose-lang/goose/testdata/examples/semantics.testSliceRef"%go.
415+
414416
Definition testFooBarMutation {ext : ffi_syntax} {go_gctx : GoGlobalContext} : go_string := "github.com/goose-lang/goose/testdata/examples/semantics.testFooBarMutation"%go.
415417

416418
Definition NewS {ext : ffi_syntax} {go_gctx : GoGlobalContext} : go_string := "github.com/goose-lang/goose/testdata/examples/semantics.NewS"%go.
@@ -2402,7 +2404,7 @@ Definition testSliceOpsⁱᵐᵖˡ {ext : ffi_syntax} {go_gctx : GoGlobalContext
24022404
Slice (go.SliceType go.uint64) ("$s", #(W64 0), #(W64 3))) in
24032405
do: ("v3" <-[go.SliceType go.uint64] "$r0");;;
24042406
let: "v4" := (GoAlloc (go.PointerType go.uint64) (GoZeroVal (go.PointerType go.uint64) #())) in
2405-
let: "$r0" := (IndexRef go.uint64 (![go.SliceType go.uint64] "x", #(W64 2))) in
2407+
let: "$r0" := (IndexRef (go.SliceType go.uint64) (![go.SliceType go.uint64] "x", #(W64 2))) in
24062408
do: ("v4" <-[go.PointerType go.uint64] "$r0");;;
24072409
let: "ok" := (GoAlloc go.bool (GoZeroVal go.bool #())) in
24082410
let: "$r0" := #true in
@@ -2563,6 +2565,19 @@ Definition testSliceAppendⁱᵐᵖˡ {ext : ffi_syntax} {go_gctx : GoGlobalCont
25632565
do: ("ok" <-[go.bool] "$r0");;;
25642566
return: (![go.bool] "ok")).
25652567

2568+
(* go: slices.go:100:6 *)
2569+
Definition testSliceRefⁱᵐᵖˡ {ext : ffi_syntax} {go_gctx : GoGlobalContext} : val :=
2570+
λ: <>,
2571+
exception_do (let: "sl" := (GoAlloc (go.SliceType go.uint64) (GoZeroVal (go.SliceType go.uint64) #())) in
2572+
let: "$r0" := ((FuncResolve go.make2 [go.SliceType go.uint64] #()) #(W64 5)) in
2573+
do: ("sl" <-[go.SliceType go.uint64] "$r0");;;
2574+
let: "ptr" := (GoAlloc (go.PointerType go.uint64) (GoZeroVal (go.PointerType go.uint64) #())) in
2575+
let: "$r0" := (IndexRef (go.SliceType go.uint64) (![go.SliceType go.uint64] "sl", #(W64 0))) in
2576+
do: ("ptr" <-[go.PointerType go.uint64] "$r0");;;
2577+
let: "$r0" := #(W64 1) in
2578+
do: ((![go.PointerType go.uint64] "ptr") <-[go.uint64] "$r0");;;
2579+
return: ((![go.uint64] (IndexRef (go.SliceType go.uint64) (![go.SliceType go.uint64] "sl", #(W64 0)))) =⟨go.uint64⟩ #(W64 1))).
2580+
25662581
(* go: struct_pointers.go:14:17 *)
25672582
Definition Bar__mutateⁱᵐᵖˡ {ext : ffi_syntax} {go_gctx : GoGlobalContext} : val :=
25682583
λ: "bar" <>,
@@ -4486,6 +4501,7 @@ Class Assumptions `{!GoGlobalContext} `{!GoLocalContext} `{!GoSemanticsFunctions
44864501
#[global] testOverwriteArray_unfold :: FuncUnfold testOverwriteArray [] (testOverwriteArrayⁱᵐᵖˡ);
44874502
#[global] testSliceLiteral_unfold :: FuncUnfold testSliceLiteral [] (testSliceLiteralⁱᵐᵖˡ);
44884503
#[global] testSliceAppend_unfold :: FuncUnfold testSliceAppend [] (testSliceAppendⁱᵐᵖˡ);
4504+
#[global] testSliceRef_unfold :: FuncUnfold testSliceRef [] (testSliceRefⁱᵐᵖˡ);
44894505
#[global] testFooBarMutation_unfold :: FuncUnfold testFooBarMutation [] (testFooBarMutationⁱᵐᵖˡ);
44904506
#[global] NewS_unfold :: FuncUnfold NewS [] (NewSⁱᵐᵖˡ);
44914507
#[global] testStructUpdates_unfold :: FuncUnfold testStructUpdates [] (testStructUpdatesⁱᵐᵖˡ);

testdata/examples/semantics/slices.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,10 @@ func testSliceAppend() bool {
9696
ok = ok && bytes[2] == byte(3)
9797
return ok
9898
}
99+
100+
func testSliceRef() bool {
101+
var sl = make([]uint64, 5)
102+
var ptr = &sl[0]
103+
*ptr = 1
104+
return (sl[0] == 1)
105+
}

testdata/examples/unittest/unittest.gold.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ Definition usesArrayElemRefⁱᵐᵖˡ {ext : ffi_syntax} {go_gctx : GoGlobalCon
697697
do: ("x" <-[go.ArrayType 2 go.string] "$r0");;;
698698
let: "$r0" := #"c"%go in
699699
do: ((IndexRef (go.ArrayType 2 go.string) (![go.ArrayType 2 go.string] "x", #(W64 1))) <-[go.string] "$r0");;;
700-
do: (let: "$a0" := (IndexRef go.string (![go.ArrayType 2 go.string] "x", #(W64 1))) in
700+
do: (let: "$a0" := (IndexRef (go.ArrayType 2 go.string) (![go.ArrayType 2 go.string] "x", #(W64 1))) in
701701
(FuncResolve takesPtr [] #()) "$a0");;;
702702
return: #()).
703703

@@ -2690,7 +2690,7 @@ Definition sliceOpsⁱᵐᵖˡ {ext : ffi_syntax} {go_gctx : GoGlobalContext} :
26902690
Slice (go.SliceType go.uint64) ("$s", #(W64 0), #(W64 3))) in
26912691
do: ("v3" <-[go.SliceType go.uint64] "$r0");;;
26922692
let: "v4" := (GoAlloc (go.PointerType go.uint64) (GoZeroVal (go.PointerType go.uint64) #())) in
2693-
let: "$r0" := (IndexRef go.uint64 (![go.SliceType go.uint64] "x", #(W64 2))) in
2693+
let: "$r0" := (IndexRef (go.SliceType go.uint64) (![go.SliceType go.uint64] "x", #(W64 2))) in
26942694
do: ("v4" <-[go.PointerType go.uint64] "$r0");;;
26952695
return: ((((((![go.uint64] "v1") +⟨go.uint64⟩ (![go.uint64] (IndexRef (go.SliceType go.uint64) (![go.SliceType go.uint64] "v2", #(W64 0))))) +⟨go.uint64⟩ (![go.uint64] (IndexRef (go.SliceType go.uint64) (![go.SliceType go.uint64] "v3", #(W64 1))))) +⟨go.uint64⟩ (![go.uint64] (![go.PointerType go.uint64] "v4"))) +⟨go.uint64⟩ (Convert go.int go.uint64 (let: "$a0" := (![go.SliceType go.uint64] "x") in
26962696
(FuncResolve go.len [go.SliceType go.uint64] #()) "$a0"))) +⟨go.uint64⟩ (Convert go.int go.uint64 (let: "$a0" := (![go.SliceType go.uint64] "x") in
@@ -2708,7 +2708,7 @@ Definition sliceOfThings__getThingRefⁱᵐᵖˡ {ext : ffi_syntax} {go_gctx : G
27082708
λ: "ts" "i",
27092709
exception_do (let: "ts" := (GoAlloc sliceOfThings "ts") in
27102710
let: "i" := (GoAlloc go.uint64 "i") in
2711-
return: (IndexRef thing (![go.SliceType thing] (StructFieldRef sliceOfThings "things"%go "ts"), ![go.uint64] "i"))).
2711+
return: (IndexRef (go.SliceType thing) (![go.SliceType thing] (StructFieldRef sliceOfThings "things"%go "ts"), Convert go.uint64 go.int (![go.uint64] "i")))).
27122712

27132713
(* go: slices.go:30:6 *)
27142714
Definition makeAliasⁱᵐᵖˡ {ext : ffi_syntax} {go_gctx : GoGlobalContext} : val :=

0 commit comments

Comments
 (0)