From 6146a3c2bc3e02aaa8bc3849738cec3af56644d5 Mon Sep 17 00:00:00 2001 From: Aaron Friel Date: Mon, 5 Dec 2022 14:37:30 -0800 Subject: [PATCH 1/4] ci: Remove page file tweak for Windows --- .github/workflows/ci-run-test.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/ci-run-test.yml b/.github/workflows/ci-run-test.yml index f882ef78d56c..62f8fdd85081 100644 --- a/.github/workflows/ci-run-test.yml +++ b/.github/workflows/ci-run-test.yml @@ -125,14 +125,6 @@ jobs: if: ${{ inputs.enable-coverage && runner.os != 'Windows' }} run: | echo "PULUMI_TEST_COVERAGE_PATH=$(pwd)/coverage" >> "$GITHUB_ENV" - # See: https://github.com/actions/virtual-environments/issues/2642#issuecomment-774988591 - - name: Configure Windows pagefile - uses: aaronfriel/action-configure-pagefile@v2.0-beta.1 - if: ${{ runner.os == 'Windows' }} - with: - minimum-size: 4GB - maximum-size: 4GB - disk-root: "D:" - name: Configure Go Cache Key env: CACHE_KEY: "${{ fromJson(inputs.version-set).go }}-${{ runner.os }}-${{ runner.arch }}" From 2c40dd9aa3d309579063412742199f332ac7e746 Mon Sep 17 00:00:00 2001 From: aq17 Date: Mon, 5 Dec 2022 13:48:45 -0800 Subject: [PATCH 2/4] Add *[TYPE] to [TYPE]ptr methods --- ...pes-to-corresponding-pulumi-ptr-types.yaml | 4 +++ .../templates/types_builtins.go.template | 6 ++++ sdk/go/pulumi/types_builtins.go | 36 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 changelog/pending/20221205--sdk--add-methods-to-cast-pointer-types-to-corresponding-pulumi-ptr-types.yaml diff --git a/changelog/pending/20221205--sdk--add-methods-to-cast-pointer-types-to-corresponding-pulumi-ptr-types.yaml b/changelog/pending/20221205--sdk--add-methods-to-cast-pointer-types-to-corresponding-pulumi-ptr-types.yaml new file mode 100644 index 000000000000..98064d91c897 --- /dev/null +++ b/changelog/pending/20221205--sdk--add-methods-to-cast-pointer-types-to-corresponding-pulumi-ptr-types.yaml @@ -0,0 +1,4 @@ +changes: +- type: feat + scope: sdk + description: Add methods to cast pointer types to corresponding Pulumi Ptr types diff --git a/sdk/go/pulumi/generate/templates/types_builtins.go.template b/sdk/go/pulumi/generate/templates/types_builtins.go.template index 0777ad28c864..5ac68f4f2a83 100644 --- a/sdk/go/pulumi/generate/templates/types_builtins.go.template +++ b/sdk/go/pulumi/generate/templates/types_builtins.go.template @@ -47,6 +47,12 @@ type {{.PtrType}} {{.ElemElementType}} func {{.Name}}(v {{.ElemElementType}}) {{.Name}}Input { return ({{.InputType}})(&v) } +func {{.Name}}FromPtr(v *{{.ElemElementType}}) {{.Name}}Input { + if v == nil { + return nil + } + return ({{.InputType}})(v) +} {{end}} {{if .DefineInputMethods}} // ElementType returns the element type of this Input ({{.ElementType}}). diff --git a/sdk/go/pulumi/types_builtins.go b/sdk/go/pulumi/types_builtins.go index f276ce12e3e3..868c49c4ecbd 100644 --- a/sdk/go/pulumi/types_builtins.go +++ b/sdk/go/pulumi/types_builtins.go @@ -1378,6 +1378,12 @@ type boolPtr bool func BoolPtr(v bool) BoolPtrInput { return (*boolPtr)(&v) } +func BoolPtrFromPtr(v *bool) BoolPtrInput { + if v == nil { + return nil + } + return (*boolPtr)(v) +} // ElementType returns the element type of this Input (*bool). func (*boolPtr) ElementType() reflect.Type { @@ -1909,6 +1915,12 @@ type float64Ptr float64 func Float64Ptr(v float64) Float64PtrInput { return (*float64Ptr)(&v) } +func Float64PtrFromPtr(v *float64) Float64PtrInput { + if v == nil { + return nil + } + return (*float64Ptr)(v) +} // ElementType returns the element type of this Input (*float64). func (*float64Ptr) ElementType() reflect.Type { @@ -2455,6 +2467,12 @@ type idPtr ID func IDPtr(v ID) IDPtrInput { return (*idPtr)(&v) } +func IDPtrFromPtr(v *ID) IDPtrInput { + if v == nil { + return nil + } + return (*idPtr)(v) +} // ElementType returns the element type of this Input (*ID). func (*idPtr) ElementType() reflect.Type { @@ -3462,6 +3480,12 @@ type intPtr int func IntPtr(v int) IntPtrInput { return (*intPtr)(&v) } +func IntPtrFromPtr(v *int) IntPtrInput { + if v == nil { + return nil + } + return (*intPtr)(v) +} // ElementType returns the element type of this Input (*int). func (*intPtr) ElementType() reflect.Type { @@ -3993,6 +4017,12 @@ type stringPtr string func StringPtr(v string) StringPtrInput { return (*stringPtr)(&v) } +func StringPtrFromPtr(v *string) StringPtrInput { + if v == nil { + return nil + } + return (*stringPtr)(v) +} // ElementType returns the element type of this Input (*string). func (*stringPtr) ElementType() reflect.Type { @@ -4539,6 +4569,12 @@ type urnPtr URN func URNPtr(v URN) URNPtrInput { return (*urnPtr)(&v) } +func URNPtrFromPtr(v *URN) URNPtrInput { + if v == nil { + return nil + } + return (*urnPtr)(v) +} // ElementType returns the element type of this Input (*URN). func (*urnPtr) ElementType() reflect.Type { From 590003f0e643e16efc4658de36a5ae3713450757 Mon Sep 17 00:00:00 2001 From: Anton Tayanovskyy Date: Mon, 5 Dec 2022 12:45:25 -0500 Subject: [PATCH 3/4] Allow opting out of PULUMI_OPTIMIZED_CHECKPOINT_PATCH --- pkg/backend/httpstate/backend.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/backend/httpstate/backend.go b/pkg/backend/httpstate/backend.go index 44d17efc3d14..c80f73ec208c 100644 --- a/pkg/backend/httpstate/backend.go +++ b/pkg/backend/httpstate/backend.go @@ -1798,6 +1798,15 @@ func doDetectCapabilities(ctx context.Context, d diag.Sink, client *client.Clien d.Warningf(diag.Message("" /*urn*/, "failed to decode capabilities: %v"), err) return capabilities{} } + + // Allow users to opt out of deltaCheckpointUpdates even if the backend indicates it should be used. This + // remains necessary while PULUMI_OPTIMIZED_CHECKPOINT_PATCH has higher memory requirements on the client and + // may cause out-of-memory issues in constrained environments. + switch strings.ToLower(os.Getenv("PULUMI_OPTIMIZED_CHECKPOINT_PATCH")) { + case "0", "false": + caps.deltaCheckpointUpdates = nil + } + return caps } From 751d7957cfbbe41cab5206befe89610478307273 Mon Sep 17 00:00:00 2001 From: Anton Tayanovskyy Date: Mon, 5 Dec 2022 15:08:35 -0500 Subject: [PATCH 4/4] Fix mapper panic on map[string]*string handling --- sdk/go/common/util/mapper/mapper_decode.go | 19 +++++----- sdk/go/common/util/mapper/mapper_test.go | 41 ++++++++++++++++++++++ 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/sdk/go/common/util/mapper/mapper_decode.go b/sdk/go/common/util/mapper/mapper_decode.go index 53d4888a28c1..9911479b4d84 100644 --- a/sdk/go/common/util/mapper/mapper_decode.go +++ b/sdk/go/common/util/mapper/mapper_decode.go @@ -151,16 +151,19 @@ func (md *mapper) adjustValueForAssignment(val reflect.Value, // A simple conversion exists to make this right. val = val.Convert(to) } else if to.Kind() == reflect.Ptr && val.Type().AssignableTo(to.Elem()) { - // If the target is a pointer, turn the target into a pointer. If it's not addressable, make a copy. - if val.CanAddr() { - val = val.Addr() + // Here the destination type (to) is a pointer to a type that accepts val. + var adjusted reflect.Value // var adjusted *toElem + if val.CanAddr() && val.Addr().Type().AssignableTo(to) { + // If taking the address of val makes this right, do it. + adjusted = val.Addr() // adjusted = &val } else { - slot := reflect.New(val.Type().Elem()) - copy := reflect.ValueOf(val.Interface()) - contract.Assert(copy.CanAddr()) - slot.Set(copy) - val = slot + // Otherwise create a fresh pointer of the desired type and point it to val. + adjusted = reflect.New(to.Elem()) // adjusted = new(toElem) + adjusted.Elem().Set(val) // *adjusted = val } + // In either case, the loop condition should be sastisfied at this point. + contract.Assert(adjusted.Type().AssignableTo(to)) + return adjusted, nil } else if val.Kind() == reflect.Interface { // It could be that the source is an interface{} with the right element type (or the right element type // through a series of successive conversions); go ahead and give it a try. diff --git a/sdk/go/common/util/mapper/mapper_test.go b/sdk/go/common/util/mapper/mapper_test.go index 1c8b88e0fa42..66b1603a049a 100644 --- a/sdk/go/common/util/mapper/mapper_test.go +++ b/sdk/go/common/util/mapper/mapper_test.go @@ -573,3 +573,44 @@ func TestBasicUnmap(t *testing.T) { assert.False(t, hash1h) } } + +func TestReproduceMapStringPointerTurnaroundIssue(t *testing.T) { + t.Parallel() + + type X struct { + Args map[string]*string `pulumi:"args,optional"` + } + + xToMap := func(build X) (map[string]interface{}, error) { + m, err := New(nil).Encode(build) + if err != nil { + return nil, err + } + return m, nil + } + + xFromMap := func(pm map[string]interface{}) (X, error) { + var build X + err := New(nil).Decode(pm, &build) + if err != nil { + return X{}, err + } + return build, nil + } + + value := "value" + expected := X{ + Args: map[string]*string{ + "key": &value, + }, + } + + encodedMap, err := xToMap(expected) + require.NoError(t, err) + t.Logf("encodedMap: %v", encodedMap) + + back, err2 := xFromMap(encodedMap) + require.NoError(t, err2) + + require.Equal(t, expected, back) +}