-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codegen update -- Assemblers, and many new representations #52
Merged
Merged
Changes from 56 commits
Commits
Show all changes
102 commits
Select commit
Hold shift + click to select a range
3f138f7
Begin reboot of codegen; also, some research.
warpfork 14e6653
Codegen now has widespread symbol customization.
warpfork cbef5c3
Fix excessing pointers in maybes.
warpfork 59c295d
Beginning of struct gen; much ado about Maybes.
warpfork 80b0ba2
Checkpoint of struct gen progress.
warpfork 96d63ad
Correct iterators for representatons of structs with absent optional …
warpfork 7ff42bd
Nicely composable NodeBuilderGenerator, +mixins.
warpfork f3be0c3
Fix basicnode maps to not wedge on repeated keys; and DRY maps and li…
warpfork fd94a06
Checkpoint of codegen'd struct assemblers.
warpfork 27873cb
ErrInvalidKey type, and use it.
warpfork 896d0e5
Late night thoughts on reducing gen type count.
warpfork 125a2a7
Fix many issues with maybes; adjunct config for if maybe is implement…
warpfork 255bbc5
Support maybe implemented using ptr.
warpfork 1a6143a
Contemplations about defaults for MaybeUsingPtr.
warpfork 6dfdc19
More smoke test types: exercise maybeptr=true.
warpfork 072098e
Tests on gen output; some fixes; working.
warpfork bcf7b05
Test null nullable field; works.
warpfork ddcf6b4
All nullable and optional cases tested & passing.
warpfork e422966
Merge branch 'codegen-how-maybe' into codegen-oppdatering
warpfork de61bf1
Couldn't resist adding a few more test cases.
warpfork f44ea65
Addntl questions on semantics of absent values.
warpfork 58aa17a
Refine nullable implementation; some more of struct map reprs.
warpfork 54f5e47
Stamp out remainder of map repr for struct.
warpfork 5f93c29
Support for struct field rename directives.
warpfork 616051d
Emit multiple packages in codegen tests. Exericse as plugins.
warpfork 5e815e5
Try using 'go test' subprocesses instead.
warpfork ad0a283
Deeper attempt to parse child 'go test'. Not good.
warpfork 04d2d3e
Merge-ignore branch 'test-codegen-using-go-test-subproc' into test-co…
warpfork 79de0e2
Complete codegen tests using plugins.
warpfork e11bc44
Smooth skips when plugins aren't available (or on request); docs on t…
warpfork 3705531
Merge branch 'test-codegen-using-plugins' into codegen-oppdatering
warpfork 62a03ee
Extract total Generate method.
warpfork a83fad3
Fix wrong constant in text matrix.
warpfork a446f41
Fix typo in error messages.
warpfork 6eafb5c
Support for generating int types.
warpfork 3d96f41
Fix gen struct repr map with no optionals.
warpfork 2e79a3e
Support for structs with stringjoin reprsentation!
warpfork 2015992
Demo: codegen matching our Map3StrInt benchmark!
warpfork 6d31b15
Remove finish callback. Much faster. Bench.
warpfork e8d9a8f
Fix use of StructField as map key.
warpfork d21dad4
Recursive structs with string representation.
warpfork d12324e
Fix some typos in kind errors.
warpfork 25dcc61
Comments speculating on how to improve templates.
warpfork 65f49f7
Fix safety in face of over-held child assemblers for struct fields th…
warpfork 5ed03b8
Checkpoint first thrust of map gen features.
warpfork 2a34785
Next checkpoint in progress towards map gen.
warpfork 81bdd93
Third checkpoint in progress towards map gen.
warpfork 7fe8c83
Refactor 'construct'->'fromString'.
warpfork fa8b487
Map gen now works.
warpfork 51d3e05
Fix typo in interface assertions.
warpfork 9c925d1
Test structs with nested structs.
warpfork 5146075
Dry up emitNativeMaybe, and apply it everywhere.
warpfork bb7c912
Several functional tests for generated maps.
warpfork d52e2c2
Recursive maps: works, and tested.
warpfork 66047ce
Terribly important character. Avoids alloc.
warpfork 3b33e05
MapNStrMap3StrInt benchmarks on codegen.
warpfork 2c41e28
Add test for maps with complex keys.
warpfork 0551903
Test for nested structs with stringjoin repr.
warpfork 5e8f180
Update struct stringjoin repr assembler.
warpfork 7975725
Remove todo comment fixed in 2c41e2827.
warpfork 0827921
List gen support, and tests.
warpfork ac7732c
Fix stutters in some generated messages.
warpfork 33c611f
The type(/style) access table is now genned.
warpfork 75595ed
Update int gen to use the Style.FromInt pattern.
warpfork ca7481a
Considering extracting some common parts.
warpfork 83bf3c0
DRY EmitTypedNodeMethodRepresentation.
warpfork 8d848ed
Typo fix in error messages in generated ints.
warpfork f6cbe84
More DRY'ing efforts in codegen.
warpfork 680f138
The string of kinds should really be lowercase.
warpfork 9737070
Comment typo fix.
warpfork ef17e64
Extract and DRY AssignNull method for most types.
warpfork 3c03a6d
AssignNull method now also DRY across reprs :D
warpfork 7cdaa71
Basically everything for scalar assemblers DRY.
warpfork 7754ce0
More extraction and DRY'ing.
warpfork 2f7df51
All the other scalars.
warpfork f1eeeaf
Comments contemplating options to DRY list repr.
warpfork 38a6fd0
the most hygenic of macros have been deployed here
warpfork 4d56c5e
Dry'ing more templates across repr-or-not.
warpfork 7ff6310
Generate list representation node.
warpfork e157f3b
Generalize more shared templates over repr.
warpfork 9cae922
Finish list repr list gen.
warpfork 160062b
Fix missing zeroing of wip pointer during nullable children in recurs…
warpfork d87c67e
Make this error less fragile.
warpfork 6c65fd6
Test for lists-of-lists and that representation-mode recursion works …
warpfork 3d4cd43
Maps now correctly stay in representation mode when read.
warpfork 6916052
comment typo fix
warpfork e9bb741
Map representations now work and correctly stay in representation mod…
warpfork e198e32
Feature table in readme!
warpfork a7e8b2f
Refresh HACKME documents.
warpfork f1f9308
Clean up minima.
warpfork 0009613
Regen the realgen package.
warpfork e9455cd
gendemo package is now real generation :3
warpfork 59b1625
Clean up notes about how gen templates are organized.
warpfork 9f0968c
Clean up docs on how/why codegen "maybe"s work.
warpfork 9d4171a
Move files to use genparts prefix consistently.
warpfork cc9f331
brief review of absent value handling policy
warpfork ec24732
More goals statements for codegen.
warpfork 87794f5
Clean out remaining wip documents.
warpfork befa498
Fix some out of date docs.
warpfork 13a3cd3
Regen gendemo package.
warpfork 6ca0abc
Merge branch 'master' into codegen-oppdatering
warpfork 21c8792
Update tests that had semantic conflicts.
warpfork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package methodsets | ||
|
||
type Thing struct { | ||
Alpha string | ||
Beta string | ||
} | ||
|
||
func (x *Thing) Pow() { | ||
x.Alpha = "base" | ||
} | ||
|
||
type ThingPrivate struct { | ||
a string | ||
b string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package crosspkg | ||
|
||
import ( | ||
"github.com/ipld/go-ipld-prime/_rsrch/methodsets" | ||
) | ||
|
||
type What struct { | ||
Alpha string | ||
Beta string | ||
} | ||
|
||
func FlipWhat(x *methodsets.Thing) *What { | ||
return (*What)(x) | ||
} | ||
|
||
type WhatPrivate struct { | ||
a string | ||
b string | ||
} | ||
|
||
//func FlipWhatPrivate(x *methodsets.ThingPrivate) *What { | ||
// return (*WhatPrivate)(x) | ||
//} | ||
// NOPE! | ||
// (thank HEAVENS.) | ||
// ./isomorphicCast.go:22:23: cannot convert x (type *methodsets.ThingPrivate) to type *WhatPrivate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package methodsets | ||
|
||
type AliasThing = Thing | ||
|
||
// func (x *AliasThing) Pow() {} | ||
// NOPE! | ||
// ./viaAliases.go:5:22: (*Thing).Pow redeclared in this block | ||
// previous declaration at ./base.go:8:6 | ||
|
||
type AliasPtr = *Thing | ||
|
||
// ^ Oddly, works. | ||
|
||
// func (x *AliasPtr) Pow() {} | ||
// NOPE! | ||
// ./aliases.go:14:6: invalid receiver type **Thing (*Thing is not a defined type) | ||
|
||
// func (x AliasPtr) Pow() {} | ||
// NOPE! | ||
// ./aliases.go:18:19: (*Thing).Pow redeclared in this block | ||
// previous declaration at ./base.go:8:6 | ||
|
||
/* | ||
Conclusion: no joy. | ||
Aliases really are a syntactic sugar thing, and do not seem to enable | ||
any interesting tricks that would not otherwise be possible, | ||
and certainly don't appear to get us closer to the "methodsets" semantic I yearn for. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package methodsets | ||
|
||
type Thing2ViaTypedef Thing | ||
|
||
// This also compiles and works if you longhand the entire struct defn again... | ||
// as long as it's identical, it works. | ||
// (This does not extend to replacing field types with other-named but structurally identical types.) | ||
|
||
func FlipTypedef(x *Thing) *Thing2ViaTypedef { | ||
return (*Thing2ViaTypedef)(x) | ||
} | ||
|
||
func (x *Thing2ViaTypedef) Pow() { | ||
x.Alpha = "typedef" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package methodsets | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/warpfork/go-wish" | ||
) | ||
|
||
func TestViaTypedef(t *testing.T) { | ||
x := Thing{"alpha", "beta"} | ||
|
||
x.Pow() | ||
Wish(t, x, ShouldEqual, Thing{"base", "beta"}) | ||
|
||
x2 := FlipTypedef(&x) | ||
Wish(t, x2, ShouldEqual, &Thing2ViaTypedef{"base", "beta"}) | ||
|
||
x2.Pow() | ||
Wish(t, x2, ShouldEqual, &Thing2ViaTypedef{"typedef", "beta"}) | ||
|
||
Wish(t, x, ShouldEqual, Thing{"typedef", "beta"}) // ! effects propagate back to original. | ||
|
||
x.Pow() | ||
Wish(t, x2, ShouldEqual, &Thing2ViaTypedef{"base", "beta"}) // ! and still also vice versa. | ||
|
||
// it's not just that we care about retaining mutability (though that's sometimes useful); | ||
// it's that a 'yes' to that directly implies 'yes' to "can we get this pov without any allocations". | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package methodsets | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
type Thing2ViaUnsafe struct { | ||
Alpha string | ||
Beta string | ||
} | ||
|
||
func FlipUnsafe(x *Thing) *Thing2ViaUnsafe { | ||
return (*Thing2ViaUnsafe)(unsafe.Pointer(x)) | ||
} | ||
|
||
func UnflipUnsafe(x *Thing2ViaUnsafe) *Thing { | ||
return (*Thing)(unsafe.Pointer(x)) | ||
} | ||
|
||
func (x *Thing2ViaUnsafe) Pow() { | ||
x.Alpha = "unsafe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package methodsets | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/warpfork/go-wish" | ||
) | ||
|
||
func TestViaUnsafe(t *testing.T) { | ||
x := Thing{"alpha", "beta"} | ||
|
||
x.Pow() | ||
Wish(t, x, ShouldEqual, Thing{"base", "beta"}) | ||
|
||
x2 := FlipUnsafe(&x) | ||
Wish(t, x2, ShouldEqual, &Thing2ViaUnsafe{"base", "beta"}) | ||
|
||
x2.Pow() | ||
Wish(t, x2, ShouldEqual, &Thing2ViaUnsafe{"unsafe", "beta"}) | ||
|
||
Wish(t, x, ShouldEqual, Thing{"unsafe", "beta"}) // ! effects propagate back to original. | ||
|
||
x.Pow() | ||
Wish(t, x2, ShouldEqual, &Thing2ViaUnsafe{"base", "beta"}) // ! and still also vice versa. | ||
|
||
// it's not just that we care about retaining mutability (though that's sometimes useful); | ||
// it's that a 'yes' to that directly implies 'yes' to "can we get this pov without any allocations". | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package crosspkg | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/warpfork/go-wish" | ||
|
||
"github.com/ipld/go-ipld-prime/_rsrch/nozeros" | ||
) | ||
|
||
func TestStuff(t *testing.T) { | ||
_ = nozeros.ExportedAlias{} // undesirable | ||
|
||
// _ = nozeros.ExportedPtr{} // undesirable | ||
// NOPE! (Success!) | ||
// ./zero.go:14:25: invalid pointer type nozeros.ExportedPtr for composite literal (use &nozeros.internal instead) | ||
|
||
v := nozeros.NewExportedPtr("woo") | ||
var typecheckMe interface{} = v | ||
v2, ok := typecheckMe.(nozeros.ExportedPtr) | ||
|
||
Wish(t, ok, ShouldEqual, true) // well, duh. Mostly we wanted to know if even asking was allowed. | ||
Wish(t, v2, ShouldEqual, v) // well, duh. But sanity check, I guess. | ||
|
||
v.Pow() // check that your IDE can autocomplete this, too. it should. | ||
|
||
// this is all the semantics we wanted; awesome. | ||
// | ||
// still unfortunate: Pow won't show up in docs, since it's on an unexported type. | ||
|
||
// exporting an alias of the non-pointer makes a hole in your guarantees, of course: | ||
var hmm nozeros.ExportedPtr | ||
hmm = &nozeros.ExportedAlias{} | ||
_ = hmm | ||
} | ||
|
||
func TestStranger(t *testing.T) { | ||
var foo nozeros.Foo | ||
// foo = &nozeros.FooData{} // undesirable | ||
// NOPE! (Success!) | ||
|
||
foo = nozeros.Foo(nil) // possible, yes. but fairly irrelevant. | ||
_ = foo | ||
|
||
v := nozeros.NewFoo("woo") | ||
|
||
Wish(t, v.Read(), ShouldEqual, "woo") | ||
|
||
v.Pow() | ||
|
||
Wish(t, v.Read(), ShouldEqual, "waht") | ||
|
||
v.Pow() | ||
|
||
t.Logf("%#v", v) // this will log the internal type name, not the exported alias. Arguably not ideal. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package nozeros | ||
|
||
type internal struct { | ||
x string | ||
} | ||
|
||
func (x *internal) Pow() {} | ||
|
||
// func (x ExportedPtr) Pow() {} // no, "invalid receiver type ExportedPtr (ExportedPtr is a pointer type)". | ||
// wait, no, this was only illegal for `type ExportedPtr *internal` -- AHHAH | ||
|
||
type ExportedAlias = internal | ||
|
||
type ExportedPtr = *internal | ||
|
||
// type ExportedPtr *internal // ALMOST works... | ||
// except somewhat bizarrely, 'Pow()' becomes undefined and invisible on the exported type. | ||
// As far as I can tell, aside from that, it's identical to using the alias. | ||
|
||
func NewExportedPtr(v string) ExportedPtr { | ||
return &internal{v} | ||
} | ||
|
||
// --- | ||
|
||
type FooData struct { | ||
x string | ||
} | ||
|
||
func (x Foo) Pow() { | ||
x.x = "waht" | ||
} | ||
func (x Foo) Read() string { | ||
return x.x | ||
} | ||
|
||
type foo FooData | ||
|
||
type Foo = *foo | ||
|
||
func NewFoo(v string) Foo { | ||
return &foo{v} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
Unwrap() error { return e.Reason }
for use withIs
andAs