nit icon indicating copy to clipboard operation
nit copied to clipboard

Modelize type intersections

Open jcbrinfo opened this issue 8 years ago • 13 comments

Add MIntersectionType to the model and use this new kind of type to enhance adaptative typing. As a side-effect, do some refactoring concerning the detection of nullables and primitive types.

For now, only essential (to avoid regressions) simplifications of type expressions are implemented.

Note: MTypeSet is designed to become the common superclass of MIntersectionType ( type intersections) and MUnionType (type unions) in future PRs.

jcbrinfo avatar Mar 26 '17 05:03 jcbrinfo

#INF7845

jcbrinfo avatar Mar 26 '17 05:03 jcbrinfo

This is quite nice. I think I need more time to review (and maybe discuss) the intersection API and implementation. However, I think the initial cleanup (and factorized maybenull) are useful alone. I suggests that you PR the cleanup part independently so it can be merged first (and faster). This will also simplify the review of the current PR.

privat avatar Mar 26 '17 20:03 privat

♻️ Fix nitcs and nitce.

jcbrinfo avatar Mar 26 '17 21:03 jcbrinfo

♻️ Take 3: Fix nitj. I totally forgot that I had to compile that one separately. Change done on nitj and nitcs are now more similar. Sorry for the mess.

jcbrinfo avatar Mar 27 '17 05:03 jcbrinfo

♻️ Add MIntersectionType::hash

jcbrinfo avatar Mar 28 '17 03:03 jcbrinfo

@xymus I agree for the “TODOs” commit. But, for the 3 other commits that impact MType::intersection, the first is the basic definition, while the other are about moving code from typing. I could split everything in 3 PRs, but I thought it would be harder to review.

jcbrinfo avatar Apr 14 '17 19:04 jcbrinfo

About the commits, I don't want you to change this PR. But I do have to insist that breaking up a single method across multiple commits does not help the review process. I tried to read commit by commit but the code was not coherent in each commit, there were useless variables and the doc described features not yet present. You must try to create commits with bigger commits encompassing larger features.

xymus avatar Apr 14 '17 20:04 xymus

♻️

  • [X] Reformat SeparateCompilerVisitor::autobox
  • [X] Rework the documentation of MType::can_be_null
  • [X] Rework the documentation of MType::intersection
  • [X] Rework the documentation of MTypeSet::mmodule
  • [X] Rework the documentation of MTypeSet::operands
  • [X] Rework the documentation of MTypeSet::separator
  • [X] Remove attribute MIntersectionType::constraints
    • [X] Rename MIntersectionType::from_constraints to from_operands
  • [X] Move the by-operands cache to the module.
  • [X] Reformat MParameterType::resolve_for_anchored

jcbrinfo avatar Apr 15 '17 20:04 jcbrinfo

♻️ Fix nitj

jcbrinfo avatar Apr 17 '17 04:04 jcbrinfo

Fails seem to be related to unavailable ports on the test runner.

libevent warning: Opening localhost:18946 failed

jcbrinfo avatar Apr 20 '17 02:04 jcbrinfo

:recycle:

  • [x] Promote resolution logic to MTypeSet.
  • [x] Order definitions in MIntersectionType by name.
  • [x] Move cache to MType so any caller of intersection benefit from it and it no longer use a set as a key.
  • [x] Cache hash, so retrieving an intersection of intersections from the cache is faster.
  • [x] Allow null anchors for MFormalType::can_be_null so nitmetrics can compile.
  • [x] Remove an unecessary redefiniton of can_be_null.

Here are the Ir counts for (cd src && ./valgrind.sh -- ../bin/nitc -o /dev/null "$module"):

Cache for intersections Cache for hash nitc.nit1 ../tests/alt/base_adaptive_full_alt2.nit
No No 10 628 637 825 53 062 955
Yes No 10 624 738 666 52 798 002
Yes Yes 10 618 383 914 52 798 022

Thank you @xymus for your precious feedback.


1 The current version of this PR.

jcbrinfo avatar May 06 '17 21:05 jcbrinfo

♻️

  • [x] Make MTypeSet::apply_to redefinable only in model.

jcbrinfo avatar May 15 '17 15:05 jcbrinfo

:recycle:

  • [x] Only compute the depth of each operand once.
  • [x] Add a to-do for ambiguous string representations.
  • [x] Move most of the implementation of undecorate to MTypeSet (and add a to-do to not forgot to override it for unions).
  • [x] Move hash near ==.
  • [x] Avoid infinite recursion in as_notnull
  • [x] Add a test that provokes an infinite recursion if intersection and as_notnull are mutually recursive.
  • [x] Import only core::kernel in test/base_adaptive_intersection_formal.nit
  • [x] Use ModelDiamond.
  • [x] Remove #alt2# for now allowed code in tests/base_adaptive_full.nit
  • [x] Commit the implementation of apply_to and as_notnull separately from the rest of MIntersectionType so the compiler is semantically valid at each commit.
  • [x] Flatten the intersections so we can compare them in the tests.
  • [x] Allow any collection of types for apply_to (no need to require a set).

Remaining discussion points:

  • The mmodule attribute.
  • The signature of apply_to.
  • full_name
  • The implementation of as_notnull.
  • Whether or not some changes should appear in the commit about nitce.

jcbrinfo avatar Jun 19 '17 04:06 jcbrinfo