Skip to content

Conversation

@gselzer
Copy link
Member

@gselzer gselzer commented Feb 10, 2020

This PR introduces Op adaptations, a reworking of the Op Transformation system currently used to change the Functional Type of Ops.

Making an adapt Op is as easy as making any other Op and is much easier than making a new OpTransformation. Each adapt Op must be a Function (since you put one Op in and get another Op out). If your adapt Op does not have OpDependencies, you can even make it a lambda!

TODO:

  • Ensure all commits build with passing tests
  • Remove all old OpTransformation related material (also old tests?)
  • Most likely we should merge Remove ops.run from codebase #40, since this work does not support OpRunners or multi-stage transformations. This branch exists on top of purge-ops-run, so if we do not merge this other PR first we will have to massage the history.
  • Test Op Adaptation Priority Hierarchy

@gselzer gselzer force-pushed the adapt-ops branch 4 times, most recently from d8d7aea to 4a9b9f9 Compare February 10, 2020 22:53
@ctrueden
Copy link
Member

@gselzer Exciting to see this progressing! Let me know when it is fully ready to go.

@gselzer gselzer force-pushed the adapt-ops branch 2 times, most recently from 6aabcd4 to 95a92ec Compare February 14, 2020 19:11
This could cause nasty ClassCastExceptions if users naively pass through
lambdas that do not provide the needed types.
Allow the IterableTypeExtractor to determine the greatest common
supertype of all of the elements in the Iterable. This required adding a
'greatest common supertype resolver' in Types.
We also generate a bunch of elementary adapt ops

Fixes made to the matcher in the process:

* Improve any checking in parameterizedTypes

Now, a Function<Function<I, O>, Function<Iterable<I>, Iterable<O>>> can
be matched to a Function<Any, Function<Iterable<Double>,
   Iterable<Double>>>

* Improve TypeVariable assignability

Sometimes TypeVariables are assigned to Anys and sometimes this is
correct. Sometimes, however, this is incorrect, and we can later assign
this TypeVariable to a concrete object. (We do have to be careful,
    though, to make sure that the TypeVariable actually is assignable to
    that Object).
When using the matcher itself to find adaptor OpCandidates, we would
only get candidates that were assignable at compile time. This is bad,
     because adaptations are runtime operations, and so long as the
     function that we get out of the adaptation is safely assignable to
     the type that was requested, the operation is safe and much more
     flexible.
This allows adaptors to adapt Function<I, O> -> Function<List<I>,
     List<O>> without creating another Op
gselzer and others added 14 commits February 14, 2020 13:23
These Ops adapt Function<I, O> to Computer<Iterable<I>, Iterable<O>> and
Function<I, O> to Computer<Iterable<I>, Iterable<O>>
These were made redundant by the autogenerated tests
TODO: Resolve createOpInstance
Will be used to test the inplace -> function adapters
Now they lazily compute the output and return an Iterator instead of a
List

Note that we also do a lot of work on the complex lift adaptors here.
This is because the output type of the the Function -> Iterable adaptors
is a Function<Iterable<I>, Iterable<O>>, no longer a
Function<Iterable<I>, List<O>>. Thus we had to change the type of these
lifters that depend on this op, namely the complex lifters
A computer should not pass the same reference for both input and output.
An inplace should not pass the same reference for both mutable input and
other input.
Note: the existing inplace -> function transformation were not ensuring
the correct behavior (i.e. that the input should not be modified) and
were anyways redundant since they were just testing functionality, so
they were deleted.

TODO: these will probabaly be expensive, so we should find a way to hint
      that it will be so
@gselzer gselzer force-pushed the adapt-ops branch 2 times, most recently from 68846d4 to cf0b75f Compare February 14, 2020 19:36
Now unnecessary since we have the adapt framework

We also remove obsolete tests (usually non-code-generated) that were
used to ensure proper transformation. They still run here, but they are
obsolete.
We ensure that higher-priority Op Adaptations are attempted before
lower-priority Op Adaptations
@ctrueden ctrueden merged commit ceca8fc into master Feb 14, 2020
@ctrueden ctrueden deleted the adapt-ops branch February 14, 2020 20:15
ctrueden added a commit that referenced this pull request May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

3 participants