Commit graph

498 commits

Author SHA1 Message Date
joeduffy cac52ae572 Fix two minor comment issues 2017-05-15 06:30:17 -07:00
joeduffy 78dc0b4a47 Add some handy internal RTTI helpers (and some tests) 2017-05-13 21:17:49 -04:00
joeduffy eee0f3b717 Fix some golint warnings 2017-05-13 20:04:35 -04:00
joeduffy 71855c7c44 Split intrinsics
This change just refactors out the dynamic intrinsics functions, from the general
intrinsics file, in preparation for some new ones.
2017-05-13 19:22:52 -04:00
joeduffy ea7658f338 Guard against nil diffs 2017-05-08 14:52:17 -05:00
joeduffy d3c1d7057b Add some tests for stable property ordering 2017-05-06 16:22:06 -07:00
joeduffy 7d8aadeb1e Implement chronological stable object keys
We need a stable object key enumeration order and we might as well leverage
ECMAScript's definition for this.  As of ES6, key ordering is specified; see
https://tc39.github.io/ecma262/#sec-ordinaryownpropertykeys.

I haven't fully implemented the "numbers come first part" (we can do this as
soon as we have support for Object.keys()), but the chronological part works.
2017-05-06 16:09:49 -07:00
joeduffy 3e73a6b8ba Add an alloc.NewDynamic helper function 2017-05-06 15:39:39 -07:00
joeduffy fb3a6612f6 Fix a lambda lexical environment bug
This addresses a bug where we did not reconstruct the correct lexical
environment when restoring a lambda's captured context.  Namely, the local
variables scope "drifted" with respect to the evaluation scope slots.

This is an example program that triggered it:

    function mkeighty() {
        let eighty = 80;
        return () => eighty;
    }
    let group = new ec2.SecurityGroup(..., {
        ingress: [ ..., fromPort: mkeighty()(), ... ],
    });

I am going to work on turning this into a regression test with my next
checkin; there's a fair bit of test infrastructure "machinery" I need
to put in place, but the time has come to lay the foundation.
2017-05-04 16:38:46 -07:00
joeduffy 240cdb8f0f Implement lambdas in the runtime
This change completes implementing lambdas in the runtime, closing
out pulumi/coconut#62.  The change is mostly straightforward, with
most changes coming down to the fact that functions may now exist
that themselves aren't definitions (like class/module members).
The function stub machinery has also been updated to retain the
environment in which a lambda was created, effectively "capturing"
the lexically available variables.  Note that this is *not* dynamic
scoping, which will be a problem down the road when/if we want to
support Ruby.  My guess is we'll just have a completely different
DynamicallyScopedLambdaExpression opcode.
2017-05-04 14:03:51 -07:00
joeduffy fde88b7cf4 Permit Statements in SequenceExpressions
The previous shape of SequenceExpression only permitted expressions
in the sequence.  This is pretty common in most ILs, however, it usually
leads to complicated manual spilling in the event that a statement is needed.
This is often necessary when, for example, a compiler is deeply nested in some
expression production, and then realizes the code expansion requires a
statement (e.g., maybe a new local variable must be declared, etc).

Instead of requiring complicated code-gen, this change permits SequenceExpression
to contain an arbitrary mixture of expression/statement prelude nodes, terminating
with a single, final Expression which yields the actual expression value.  The
runtime bears the burden of implementing this which, frankly, is pretty trivial.
2017-05-04 10:54:07 -07:00
joeduffy 1e67162331 Fix a couple silly mistakes 2017-05-04 09:53:52 -07:00
joeduffy 4e5140251b Implement support for computed property initializers
I've tripped over pulumi/coconut#141 a few times now, particularly with
the sort of dynamic payloads required when creating lambdas and API gateways.
This change implements support for computed property initializers.
2017-05-01 17:11:57 -07:00
joeduffy 6902d7e1b2 Update AWS Lambdas to take archives, not assets 2017-05-01 09:38:23 -07:00
joeduffy 335ea01275 Implement archives
Our initial implementation of assets was intentionally naive, because
they were limited to single-file assets.  However, it turns out that for
real scenarios (like lambdas), we want to support multi-file assets.

In this change, we introduce the concept of an Archive.  An archive is
what the term classically means: a collection of files, addressed as one.
For now, we support three kinds: tarfile archives (*.tar), gzip-compressed
tarfile archives (*.tgz, *.tar), and normal zipfile archives (*.zip).

There is a fair bit of library support for manipulating Archives as a
logical collection of Assets.  I've gone to great length to avoid making
copies, however, sometimes it is unavoidable (for example, when sizes
are required in order to emit offsets).  This is also complicated by the
fact that the AWS libraries often want seekable streams, if not actual
raw contiguous []byte slices.
2017-04-30 12:37:24 -07:00
joeduffy 0e16aa5d93 Make resource names the first constructor parameter
This reverts back to the old style of having the resource name as its
first parameter in the generated package.  Stylistically, this reads a
little nicer, and also ensures we don't need to rewrite all our existing
samples/test cases, etc.
2017-04-29 15:58:34 -07:00
joeduffy fa24d436e3 Unpointerize some types
In a few places, an IDL type will be a pointer, but the resulting
RPC code would, ideally, be the naked type.  Namely, in both resource
and asset cases, they are required to be pointers in the IDL (because
they are by-pointer by nature), but the marshaled representations need
not be pointers.  This change depointerizes such types in the RPC
unless, of course, they are optional in which case pointers still make
sense.  This avoids some annoying dereferencing and is the kind of thing
we want to do sooner before seeing widespread use.
2017-04-29 15:38:56 -07:00
joeduffy fe93f5e76f Strongly type resource IDs in the IDL/RPC/Providers
This change simply uses the `resource.ID` type in all the places
where it belongs, rather than using `string`-typed resource IDs.
2017-04-29 13:27:39 -07:00
joeduffy b381d23393 Ensure all errors correlate back to the IDL source 2017-04-28 15:21:22 -07:00
joeduffy 6952fd55f0 Track named resources
This change adds some conditional output that depends on whether a
named resource was contained in a file or not.  This eliminates some
compiler errors in the generated code when using manually-named
resources.
2017-04-28 15:03:24 -07:00
joeduffy 7e057cd1b5 Permit maps in IDL 2017-04-28 15:03:09 -07:00
joeduffy 77fc639286 Don't mangle RPC package names 2017-04-28 12:42:31 -07:00
joeduffy 1489a73b18 Convert the AWS Lambda module to CIDLC 2017-04-28 12:27:19 -07:00
joeduffy 5ae168d23c Emit interface{} as just interface{} 2017-04-28 12:09:17 -07:00
joeduffy 40ac0a1d2b Support assets in the IDL 2017-04-28 12:07:49 -07:00
joeduffy f5c6af505a Properly fetch pointer elements 2017-04-28 11:46:35 -07:00
joeduffy 42ce8744ce Update the code-gen warning text 2017-04-28 11:35:33 -07:00
joeduffy 19577d67f0 Don't emit imports for zero-resource cases 2017-04-28 11:05:34 -07:00
joeduffy 75a897c23f Map interface{} RPC projections correctly
A property whose type is `interface{}` in the IDL ought to be projected
as a "JSON-like" map, just like it is on the Coconut package side of things,
which means a `map[string]interface{}`.
2017-04-28 10:58:27 -07:00
joeduffy 954d594e94 Rename --recurse to --recursive
My muscle memory kicked in (grep, et al), and then I realized the
name wasn't quite right.  This rights a wrong.
2017-04-28 10:37:05 -07:00
joeduffy af3949509a Implement CIDLC support for package imports
This change correctly implements package/module resolution in CIDLC.
For now, this only works for intra-package imports, which is sufficient
for now.  Eventually we will need to support this (see pulumi/coconut#138).
2017-04-28 10:31:18 -07:00
joeduffy 46227870e4 Implement a few CIDLC improvements
* Allow `interface{}` to mean "weakly typed property bag."

* Allow slices in IDL types.

* Permit the package base as an argument.
2017-04-27 15:40:51 -07:00
joeduffy dd032e0784 Make IsResource tolerant of types.Named types 2017-04-27 11:52:59 -07:00
joeduffy 47ef3f673b Rename PreviewUpdate (again)
Unfortunately, this wasn't a great name.  The old one stunk, but the
new one was misleading at best.  The thing is, this isn't about performing
an update -- it's about NOT doing an update, depending on its return value.
Further, it's not just previewing the changes, it is actively making a
decision on what to do in response to them.  InspectUpdate seems to convey
this and I've unified the InspectUpdate and Update routines to take a
ChangeRequest, instead of UpdateRequest, to help imply the desired behavior.
2017-04-27 11:18:49 -07:00
joeduffy 43bb3ec766 Reject non-pointer optional fields
This change rejects non-pointer optional fields in the IDL.  Although
there is no reason this couldn't work, technically speaking, it's almost
always certainly a mistake.  Better to issue an error about it; in the
future, we could consider making this a warning.
2017-04-27 11:03:13 -07:00
joeduffy 3f54c672be Fix/alter a few aspects of RPC code-generation
* Use --out-rpc, rather than --out-provider, since rpc/ is a peer to provider/.

* Use strongly typed tokens in more places.

* Append "rpc" to the generated RPC package names to avoid conflicts.

* Change the Check function to return []mapper.FieldError, rather than
  mapper.DecodeError, to make the common "no errors" case easier (and to eliminate
  boilerplate resulting in needing to conditionally construct a mapper.DecodeError).

* Rename the diffs argument to just diff, matching the existing convention.

* Automatically detect changes to "replaces" properties in the PreviewUpdate
  function.  This eliminates tons of boilerplate in the providers and handles the
  90% common case for resource recreation.  It's still possible to override the
  PreviewUpdate logic, of course, in case there is more sophisticated recreation
  logic necessary than just whether a property changed or not.

* Add some comments on some generated types.

* Generate property constants for the names as they will appear in weakly typed
  property bags.  Although the new RPC interfaces are almost entirely strongly
  typed, in the event that diffs must be inspected, this often devolves into using
  maps and so on.  It's much nicer to say `if diff.Changed(SecurityGroup_Description)`
  than `if diff.Changed("description")` (and catches more errors at compile-time).

* Fix resource ID generation logic to properly fetch the Underlying() type on
  named types (this would sometimes miss resources during property analysis, emitting
  for example `*VPC` instead of `*resource.ID`).
2017-04-27 10:36:22 -07:00
joeduffy 164d4db30a Implement CIDLC RPC code generation
This change implements the boilerplate RPC stub generation for CIDLC
resource providers.  This includes a lot of the marshaling goo required
to bridge between the gRPC plugin interfaces and the strongly typed
resource types and supporting marshalable structures.

This completes the major tasks of implementing CIDLC (pulumi/coconut#133),
and I have most of the AWS package running locally on it.  There are
undoubtedly bugs left to shake out, but no planned work items remain.
2017-04-27 07:33:00 -07:00
joeduffy 507a2609a7 Add an initial implementation of CIDLC
This is an initial implementation of the Coconut IDL Compiler (CIDLC).
This is described further in
https://github.com/pulumi/coconut/blob/master/docs/design/idl.md,
and the work is tracked by coconut/pulumi#133.

I've been kicking the tires with this locally enough to checkpoint the
current version.  There are quite a few loose ends not yet implemented,
most of them minor, with the exception of the RPC stub generation which
I need to flesh out more before committing.
2017-04-25 15:05:51 -07:00
joeduffy 8c58950639 Tolerate nils in output property marshaling 2017-04-25 14:04:22 -07:00
joeduffy 1edced2d4b Add the ability to convert structs to PropertyMaps 2017-04-21 15:27:32 -07:00
joeduffy d6abea728c Add outputs to the Create provider's return
In order to support output properties (pulumi/coconut#90), we need to
modify the Create gRPC interface for resource providers slightly.  In
addition to returning the ID, we need to also return any properties
computed by the AWS provider itself.  For instance, this includes ARNs
and IDs of various kinds.  This change simply propagates the resources
but we don't actually support reading the outputs just yet.
2017-04-21 14:15:06 -07:00
joeduffy aa44b46608 Lower instanceof in CocoJS; implement IsInst in CocoIL 2017-04-20 17:38:15 -07:00
joeduffy 0b6e262b46 Rename resource provider methods
This change renames two provider methods:

    * Read becomes Get.

    * UpdateImpact becomes PreviewUpdate.

These just read a whole lot nicer than the old names.
2017-04-20 14:09:00 -07:00
joeduffy 94e072c653 Add a TryLoadDynamicExpression IL opcode
This change introduces TryLoadDynamicExpression.  This is similar to
the existing LoadDynamicExpression opcode, except that it will return
null in response to a missing member (versus the default of raising
an exception).  This is to enable languages like JavaScript to encode
operations properly (which always yields undefined/nulls), while still
catering to languages like Python (which throw exceptions).
2017-04-19 16:49:59 -07:00
joeduffy 53e7bfbb86 Rearrange the way stderr/stdout is handled for plugins
The order of operations for stderr/stdout monitoring with plugins
managed to hide some important errors.  For example, if something
was written to stderr *before* the port was parsed from stdout, a
very possible scenario if the plugin fails before it has even
properly sarted, then we would silently drop the stderr on the floor
leaving behind no indication of what went wrong.  The new ordering
ensures that stderr is never ignored with some minor improvements
in the case that part of the port is parsed from stdout but it
ultimately ends in an error (e.g., if an EOF occurs prematurely).
2017-04-19 15:01:04 -07:00
joeduffy f429bc6a0c Use github.com/pkg/errors for errors
This change moves us over to the github.com/pkg/errors package to
encourage the addition of more context associated with failures.
2017-04-19 14:46:50 -07:00
joeduffy 958d67d444 Move NewCheckResponse into coconut/pkg/resource package 2017-04-19 14:25:49 -07:00
joeduffy 936d3f45e6 Fix another package name reference 2017-04-19 14:20:12 -07:00
joeduffy 98961b706a Permit package name hyphens in one more place
...missed one.
2017-04-19 11:34:36 -07:00
joeduffy 034fc3bf67 Permit dashes in package names
Right now, we reject dashes in package names.  I've hit this a few times and it annoys
me each time.  (It would seem to makes sense to permit hyphens in package names, given
that [almost?] every other package manager on Earth does...)

No more!  Hyphens welcome!
2017-04-19 10:53:14 -07:00