1. 22 Aug, 2021 1 commit
  2. 16 Aug, 2021 1 commit
  3. 29 Jul, 2021 1 commit
  4. 03 Jun, 2021 1 commit
    • Daniel Martí's avatar
      node/tests: add more extensive scalar kind tests · b6e2b10f
      Daniel Martí authored
      It covers AssignKind, AssignNode, and AsKind for every combination of
      assembler kind and method.
      
      We also verify that a constructed scalar node behaves the same with
      AsKind when using its representation, like the old test.
      
      There's effectively a triple loop as a test table, so the subtest name
      has up to three components separated by dashes, such as:
      
      	TestSchema/Scalars/Bytes-AssignNode-String
      
      We also use this test as a demo of quicktest instead of go-wish.
      
      Finally, adapt bindnode to pass these tests just like codegen. This was
      mainly a bunch of TODOs in the relevant methods.
      b6e2b10f
  5. 02 Jun, 2021 1 commit
    • Daniel Martí's avatar
      node/tests: put most of the schema test cases here · 5b6e1d30
      Daniel Martí authored
      Along with a generic Engine interface, so that they can be reused for
      other ipld.Node implementations, such as bindnode.
      
      node/bindnode will start using these in a follow-up commit, since this
      one is large enough as is.
      
      Tested that all three forms of testing schema/gen/go still work:
      
      	go test
      
      	CGO_ENABLED=0 go test
      
      	go test -tags=skipgenbehavtests
      5b6e1d30
  6. 25 May, 2021 1 commit
    • Daniel Martí's avatar
      add DeepEqual and start using it in tests · 6d29b3c3
      Daniel Martí authored
      The funciton is carefully documented via godoc, so I'm not going to
      attempt to document it here again. But as a high-level summary, it's
      like a reflect.DeepEqual applied to the ipld.Node interface rather than
      reflect.Value.
      
      The only other two noteworthy details are that errors are treated as
      panics, and Links are compared directly via ==.
      
      Finally, we add table-driven tests to ensure all edge cases work.
      
      Fixes #173.
      6d29b3c3
  7. 09 Apr, 2021 3 commits
    • Daniel Martí's avatar
      schema/gen/go: apply gofmt automatically · 4bb2f097
      Daniel Martí authored
      Now that we buffer the output, using go/format is trivial.
      
      This makes the default behavior better, and means not having to use an
      extra gofmt go:generate step everywhere.
      4bb2f097
    • Daniel Martí's avatar
      schema/gen/go: fix remaining vet warnings on generated code · 2359e698
      Daniel Martí authored
      And re-generate all code in this module.
      
      This gets us to a point where go-codec-dagpb has zero vet warnings, for
      example. schema/dmt still has a few warnings, but those are trickier to
      fix, so will require another PR.
      2359e698
    • Daniel Martí's avatar
      schema/gen/go: batch file writes via a bytes.Buffer · 88f72f58
      Daniel Martí authored
      With this change, running 'go generate ./...' on the entire module while
      running gopls on one of its files drops gopls's CPU spinning from ~25s
      to well under a second. They should improve that anyway, but there's no
      reason for the tens of thousands of tiny FS writes on our end either.
      
      The time to run 'go generate ./...' itself is largely unaffected; it
      goes from ~1.2s to ~1.1s, judging by a handful of runs.
      88f72f58
  8. 07 Apr, 2021 1 commit
    • Daniel Martí's avatar
      schema/gen/go: avoid Maybe pointers for small types · f3d42e04
      Daniel Martí authored
      If we know that a schema type can be represented in Go with a small
      amount of bytes, using a pointer to store its "maybe" is rarely a good
      idea. For example, an optional string only weighs twice as much as a
      pointer, so a pointer adds overhead and will barely ever save any
      memory.
      
      Add a function to work out the byte size of a schema.TypeKind, relying
      on reflection and the basicnode package. Debug prints are also present
      if one wants to double-check the numbers. As of today, they are:
      
      	sizeOf(small): 32 (4x pointer size)
      	sizeOf(Bool): 1
      	sizeOf(Int): 8
      	sizeOf(Float): 8
      	sizeOf(String): 16
      	sizeOf(Bytes): 24
      	sizeOf(List): 24
      	sizeOf(Map): 32
      	sizeOf(Link): 16
      
      Below is the result on go-merkledag's BenchmarkRoundtrip after
      re-generating go-codec-dagpb with this change. Note that the dag-pb
      schema contains multiple optional fields, such as strings.
      
      	name         old time/op    new time/op    delta
      	Roundtrip-8    4.24µs ± 3%    3.78µs ± 0%  -10.87%  (p=0.004 n=6+5)
      
      	name         old alloc/op   new alloc/op   delta
      	Roundtrip-8    6.38kB ± 0%    6.24kB ± 0%   -2.26%  (p=0.002 n=6+6)
      
      	name         old allocs/op  new allocs/op  delta
      	Roundtrip-8       103 ± 0%        61 ± 0%  -40.78%  (p=0.002 n=6+6)
      
      Schema typekinds which don't directly map to basicnode prototypes, such
      as structs and unions, are left as a TODO for now.
      
      I did not do any measurements to arrive at the magic number of 4x, which
      is documented in the code. We might well increase it in the future, with
      more careful benchmarking. For now, it seems like a conservative starting
      point that should cover all basic types.
      
      Finally, re-generate within this repo.
      f3d42e04
  9. 23 Mar, 2021 2 commits
  10. 25 Feb, 2021 1 commit
    • Eric Myhre's avatar
      schema compiler: example of how migrating tests to new compiler will look. · 13d3707d
      Eric Myhre authored
      This'll probably be a lot of grind to refactor, but otherwise isn't
      a huge jump semantically.
      
      I waffled on sprinting straight ahead to writing schema DMT as JSON,
      and using those as the test fixture input.  On the one hand: it would
      be nice to get that much closer to purely textual test fixtures.
      On the other hand, it's really verbose, and I don't want to (long run,
      we'll use schema DSL for this, and while we'll also save the DMT
      fixtures, they should ideally probably mostly be generated and just
      human-checked rather than human-penned);
      and also, since we don't have implicits implemented correctly yet,
      we'd need to update all that JSON again anyway once that feature is
      complete... which pushes it overall to a net "nah".
      13d3707d
  11. 24 Jan, 2021 1 commit
    • Eric Myhre's avatar
      schema: so much boilerplate for feeding information to the Compiler that I... · d74ecb3e
      Eric Myhre authored
      schema: so much boilerplate for feeding information to the Compiler that I wrote another supplementary code generator.
      
      (I'm getting very weary of golang.)
      
      This new bit of codegen makes the compiler.go file fairly readable
      again, though, so I'm satisfied with it.
      
      The Compiler API is now complete enough that I can start repairing
      other things to use it properly.  The schemadmt.Schema.Compile()
      function and all of its helpers compile again now.  So does *most*
      of the whole codegen system... with the notable exception of all
      the hardcoded typesystem spawning which used the old placeholder
      methods which have now been stricken.
      
      TypeSystem now maintains order.  This allowed me to remove some
      sort operations from the code generator.  This also means the next
      time any existing codegen is re-run, the output file will shift
      significantly.  However, it shouldn't do so again in the future.
      d74ecb3e
  12. 21 Jan, 2021 1 commit
    • Daniel Martí's avatar
      schema/gen/go: cache genned code in os.TempDir · 0b3adb9d
      Daniel Martí authored
      This means we no longer clutter the repository with lots of files, even
      if they are git-ignored. It's always a bit of a red flag when you run
      "go test ./..." and the result is a bunch of leftover files.
      
      We still want to keep the files around, for the sake of Go's build
      cache. And we still want their paths to be static between "go test"
      runs. So put them in a static dir under os.TempDir.
      
      This does mean that concurrent runs of these tests will likely not work
      well. I don't imagine that's going to be a problem anytime soon, though.
      If it really becomes a problem in the future, we could figure something
      out like grabbing a file lock for the directory.
      
      The idea behind using os.TempDir is that it will likely remain in place
      between a number of "go test" runs within a hacking session, but it will
      be eventually cleaned up by the system, such as when rebooting.
      
      Note that we need to use globbing since one can't build "proper
      packages" located outside a module. The only exception is building an
      ad-hoc set of explicit Go files. While at it, use filepath.Join, to be
      nice.
      0b3adb9d
  13. 18 Jan, 2021 1 commit
  14. 10 Jan, 2021 2 commits
    • Daniel Martí's avatar
      schema/gen/go: remove two common subtest levels · d02c3602
      Daniel Martí authored
      Practically every subtest ends up at 7 or so levels of names, like:
      
      	TestMapsContainingMaybe/maybe-using-ptr/generate/compile/bhvtest/non-nullable/typed-create
      
      However, note that the "generate" and "compile" levels are always there,
      so their presence just adds verbosity in the output and makes the
      developer's life more difficult.
      
      Extremely nested sub-tests are already rare, so at least we can just
      keep the components that add useful information in the output.
      
      "bhvtest" is also pretty redundant, but that one actually matters - its
      subtest can be skipped depending on build tags.
      d02c3602
    • Daniel Martí's avatar
      schema/gen/go: please vet a bit more · 6796504d
      Daniel Martí authored
      In particular, this removes ~50 out of the 2.7k warnings in 'go vet
      ./...' in this repository. Mainly, the "unreachable code" ones.
      
      This was caused by edge cases in some of the generated code which caused
      an unconditional return or panic statement to be followed by other code.
      Fix all of them with a bit more template logic.
      
      Some of the Next methods go a bit further. If they serve no purpose as
      the switch has no cases to be matched, just unconditionally return an
      error. In the future we can perhaps reuse a single function for that.
      
      Finally, I was having a hard time actually following the logic in
      kindedUnionNodeAssemblerMethodTemplateMunge, so I've indented the code a
      bit to follow the template logic and scoping.
      
      These changes move us towards pleasing vet, which is nice, but also make
      the code waste a bit less space.
      6796504d
  15. 07 Jan, 2021 1 commit
  16. 03 Jan, 2021 4 commits
  17. 31 Dec, 2020 1 commit
  18. 27 Dec, 2020 1 commit
  19. 25 Dec, 2020 1 commit
    • Daniel Martí's avatar
      all: rename schema.Kind to TypeKind, ipld.ReprKind to Kind · 2d7d25c4
      Daniel Martí authored
      As discussed on the issue thread, ipld.Kind and schema.TypeKind are more
      intuitive, closer to the spec wording, and just generally better in the
      long run.
      
      The changes are almost entirely automated via the commands below. Very
      minor changes were needed in some of the generators, and then gofmt.
      
      	sed -ri 's/\<Kind\(\)/TypeKind()/g' **/*.go
      	git checkout fluent # since it uses reflect.Value.Kind
      
      	sed -ri 's/\<Kind_/TypeKind_/g' **/*.go
      	sed -i 's/\<Kind\>/TypeKind/g' **/*.go
      	sed -i 's/ReprKind/Kind/g' **/*.go
      
      Plus manually undoing a few renames, as per Eric's review.
      
      Fixes #94.
      2d7d25c4
  20. 17 Dec, 2020 1 commit
    • Daniel Martí's avatar
      all: rename AssignNode to ConvertFrom · 6e6625bd
      Daniel Martí authored
      This should be more intuitive to Go programmers, since assignments are
      generally trivial operations, but conversions imply that extra work
      might be needed to adapt the value to fit in the recipient.
      
      The entire change is just:
      
      	sed -ri 's/AssignNode/ConvertFrom/g' **/*.go
      
      Downstream users can very likely use the same line to fix their function
      declarations and calls.
      
      Fixes #95.
      6e6625bd
  21. 16 Dec, 2020 1 commit
    • Daniel Martí's avatar
      all: rewrite interfaces and APIs to support int64 · f6e9a891
      Daniel Martí authored
      We only supported representing Int nodes as Go's "int" builtin type.
      This is fine on 64-bit, but on 32-bit, it limited those node values to
      just 32 bits. This is a problem in practice, because it's reasonable to
      want more than 32 bits for integers.
      
      Moreover, this meant that IPLD would change behavior if built for a
      32-bit platform; it would not be able to decode large integers, for
      example, when in fact that was just a software limitation that 64-bit
      builds did not have.
      
      To fix this problem, consistently use int64 for AsInt and AssignInt.
      
      A lot more functions are part of this rewrite as well; mainly, those
      revolving around collections and iterating. Some might never need more
      than 32 bits in practice, but consistency and portability is preferred.
      Moreover, many are interfaces, and we want IPLD interfaces to be
      flexible, which will be important for ADLs.
      
      Below are some GNU sed lines which can be used to quickly update
      function signatures to use int64:
      
      	sed -ri 's/(func.* AsInt.*)\<int\>/\1int64/g' **/*.go
      	sed -ri 's/(func.* AssignInt.*)\<int\>/\1int64/g' **/*.go
      	sed -ri 's/(func.* Length.*)\<int\>/\1int64/g' **/*.go
      	sed -ri 's/(func.* LookupByIndex.*)\<int\>/\1int64/g' **/*.go
      	sed -ri 's/(func.* Next.*)\<int\>/\1int64/g' **/*.go
      	sed -ri 's/(func.* ValuePrototype.*)\<int\>/\1int64/g' **/*.go
      
      Note that the function bodies, as well as the code that calls said
      functions, may need to be manually updated with the integer type change.
      That cannot be automated, because it's possible that an automated fix
      would silently introduce potential overflows not being handled.
      
      Some TODOs and FIXMEs for overflow checks are removed, since we remove
      some now unnecessary int64->int conversions. On the other hand, the
      older codecs based on refmt need to gain some overflow check TODOs,
      since refmt uses ints. That is okay for now, since we'll phase out refmt
      pretty soon.
      
      While at it, update codectools to use int64 for token Length fields, so
      that it properly supports full IPLD integers without machine-dependent
      behavior and overflow checks. The budget integer is also updated to be
      int64, since the lengths it uses are now int64.
      
      Note that this refactor needed changes to the Go code generator as well
      as some of the tests, for the purpose of updating all the code.
      
      Finally, note that the code-generated iterator structs do not use int64
      fields internally, even though they must return int64 numbers to
      implement the interface. This is because they use the numeric fields to
      count up to a small finite amount (such as the number of fields in a Go
      struct), or up to the length of a map/slice. Neither of them can ever
      outgrow "int".
      
      Fixes #124.
      f6e9a891
  22. 13 Dec, 2020 2 commits
  23. 04 Dec, 2020 2 commits
    • Eric Myhre's avatar
      codegen: assembler for struct with map representation now validates all... · f8d654da
      Eric Myhre authored
      codegen: assembler for struct with map representation now validates all non-optional fields are present.
      
      This continues what https://github.com/ipld/go-ipld-prime/pull/111/ did
      and adds the same logic to the map representation.  The actual state
      tracking works the same way (and was mostly already there).
      
      Rearranged the tests slightly.
      
      Made error messages include both field name and serial key when they
      differ due to a rename directive.  (It's possible this error would get
      nicer if it used a list of StructField instead of just strings, but it
      would also get more complicated.  Maybe revisit later.)
      f8d654da
    • Daniel Martí's avatar
      all: fix a lot of "unkeyed literal" vet warnings · 354f194f
      Daniel Martí authored
      Reduces the output of 'go vet ./...' from 374 lines to 96. Many warnings
      remain, but I have lost my patience for today.
      
      Most of the changes below were automated, especially the single-line
      mixins expressions. Unfortunately, many of the Traits structs required
      manual copy-pasting.
      354f194f
  24. 30 Nov, 2020 1 commit
    • Will's avatar
      Allow overriden types (#116) · fe47b7f0
      Will authored
      This change will look at the destination package that codegen is being built into, and will skip generation of types that are already declared by files not prefixed with `ipldsch_`.
      
      This isn't the cleanest escape-hatch, but it's a start.
      fe47b7f0
  25. 17 Nov, 2020 4 commits
    • Will Scott's avatar
      add import to ipld in ipldsch_types.go · 9656675b
      Will Scott authored
      cleanup from #105
      9656675b
    • Eric Myhre's avatar
      codegen: rename files. · 32e66f20
      Eric Myhre authored
      An underscore; and less "gen", because reviewers indicated it felt redundant.
      32e66f20
    • Eric Myhre's avatar
      codegen: deterministic order for types in output. · 4f333954
      Eric Myhre authored
      I'd still probably prefer to replace this with simply having a stable
      order that is carried through consistently, but that remains blocked
      behind getting self-hosted types, and while it so happens I also got
      about 80% of the way there on those today, the second 80% may take
      another day.  Better make this stable rather than wait.
      4f333954
    • Eric Myhre's avatar
      codegen: rearrange output into finite number of files. · 76193e5d
      Eric Myhre authored
      Also, emit some comments around the type definitions.
      
      The old file layout is still available, but renamed to GenerateSplayed.
      It will probably be removed in the future.
      
      The new format does not currently have stable output order.
      I'd like to preserve the original order given by the schema,
      but our current placeholder types for schema data don't have this.
      More work needed on this.
      76193e5d
  26. 14 Nov, 2020 3 commits