1. 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
  2. 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
  3. 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
  4. 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
  5. 10 Sep, 2020 1 commit
    • Daniel Martí's avatar
      schema/gen/go: make all top-level tests parallel · 35003242
      Daniel Martí authored
      They do quite a lot of work, including setting up a type system,
      generating Go code, and building it.
      
      This package is by far the slowest to test. On a warm cache, 'go test
      -count=1 ./...' shows all packages under 0.2s, while this one sits at
      ~1.5s.
      
      1.5s is not unreasonable with a warm cache, but we can bring that down
      to 0.6s on my quad-core laptop by just making all tests parallel. Note
      that sub-tests aren't parallel for now, since there are multiple layers
      of them and I'm not sure I even follow what's going on.
      
      Mac is also disabled for the time being, since it seems to time out too
      often.
      35003242
  6. 09 Jul, 2020 1 commit
    • Eric Myhre's avatar
      Refactor the schema.Type info to support cycles. · 47abab45
      Eric Myhre authored
      This is full of mundane plonking away at adding stars and ampersands,
      of which approximately none are interesting.
      
      (I'm particularly frustrated by this because these are all placeholder
      types, and we're getting *very* close to replacing them, as we get
      closer and closer to self-hosting... at which point all of this bonking
      about will be made totally irrelevant.  And yet to close the last mile,
      these "small" fixes are surprisingly irritating.  Ah well.)
      
      The bits that *are* interesting:
      
      - the Spawn functions for type info now take strings rather than types
      (so that they don't provoke a cycle problem for the user when
      constructing the information to describe cyclic type info);
      
      - all of the Type info structure hold a pointer to the TypeSystem, and
      use that to look up reified Type info for related types, so that their
      methods don't force the caller to do that themselves.
      
      (The TypeSystem pointer was already there, amusingly; just never before
      initialized, because it hadn't turned out to be load-bearing yet.)
      
      It also would've been possible to just change all the methods on the
      Type types to return TypeName rather than full Type info.  That would
      avoid the need to use a TypeSystem pointer.  I didn't because:
      
      Overall, this was done in such a way as to minimize the diff that
      impacts within the templates.  This was a goal because updating
      templates is a fair bit more work than other code due to the weak
      compiler support.  And we'll end up reviewing and changing these
      methods when we get to our goal of self-hosting generation of the
      schema types from the schema-schema, so, it's not worth pushing around
      diffs in that same area when they'd be sure to be churned under soon.
      47abab45
  7. 29 Jun, 2020 1 commit
  8. 26 Jun, 2020 1 commit
  9. 22 May, 2020 1 commit
  10. 24 Apr, 2020 1 commit
    • Eric Myhre's avatar
      List gen support, and tests. · 0827921d
      Eric Myhre authored
      These are getting increasingly straightforward as most of the hard
      problems have been ironed out already when getting the other recursives
      (maps and structs) sorted.
      
      Now, we just need to stamp out the rest of the scalars, and I think
      this codegen stuff is at least early-alpha level usable!
      
      Also in this commit: added some new error types and fixed up the
      basicnode.List implementation to use it, removing some todos there.
      0827921d