Skip to content
This repository has been archived by the owner on Jul 13, 2019. It is now read-only.

Commit

Permalink
Remove gs-collections in favour of vavr
Browse files Browse the repository at this point in the history
This replaces all uses of gs-collections with the immutable
collections from Vavr.

Fix #25
  • Loading branch information
io7m committed Nov 16, 2017
1 parent 735abef commit 4e75bc5
Show file tree
Hide file tree
Showing 54 changed files with 1,155 additions and 931 deletions.
9 changes: 7 additions & 2 deletions README-CHANGES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@
</c:change>
</c:changes>
</c:release>
<c:release date="2017-11-16T18:14:42+00:00" ticket-system="com.github.io7m.jpra" version="0.7.0">
<c:release date="2017-11-16T20:02:28+00:00" ticket-system="com.github.io7m.jpra" version="0.7.0">
<c:changes>
<c:change compatible="false" date="2017-11-16T00:00:00+00:00" summary="All modules are now Java 9 modules. JDK 9 is now required."/>
<c:change compatible="false" date="2017-11-16T18:14:42+00:00" summary="Removed dependency on com.io7m.jnull."/>
<c:change compatible="false" date="2017-11-16T00:00:00+00:00" summary="Removed dependency on com.io7m.jnull."/>
<c:change compatible="false" date="2017-11-16T20:02:28+00:00" summary="Replace gs-collections with Vavr">
<c:tickets>
<c:ticket id="25"/>
</c:tickets>
</c:change>
</c:changes>
</c:release>
</c:releases>
Expand Down
8 changes: 0 additions & 8 deletions com.io7m.jpra.compiler.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.goldmansachs</groupId>
<artifactId>gs-collections-api</artifactId>
</dependency>
<dependency>
<groupId>com.goldmansachs</groupId>
<artifactId>gs-collections</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.io7m.jpra.compiler.core;

import com.gs.collections.api.list.ImmutableList;
import com.io7m.jlexing.core.LexicalPosition;
import com.io7m.jpra.compiler.core.checker.JPRACompilerCheckerException;
import com.io7m.jpra.compiler.core.parser.JPRACompilerParseException;
Expand All @@ -26,6 +25,7 @@
import com.io7m.jpra.model.PackageImport;
import com.io7m.jpra.model.loading.JPRAModelCircularImportException;
import com.io7m.junreachable.UnreachableCodeException;
import io.vavr.collection.List;

import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -108,7 +108,7 @@ private static void onCircularImportException(
final PrintWriter w,
final JPRAModelCircularImportException e)
{
final ImmutableList<PackageImport> imports = e.getImports();
final List<PackageImport> imports = e.getImports();

printLex(
w, imports.get(0).getTo().getLexicalInformation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@

package com.io7m.jpra.compiler.core.checker;

import com.gs.collections.api.list.ImmutableList;
import com.gs.collections.api.list.MutableList;
import com.gs.collections.api.map.ImmutableMap;
import com.gs.collections.api.map.MutableMap;
import com.gs.collections.impl.factory.Lists;
import com.gs.collections.impl.factory.Maps;
import com.io7m.jaffirm.core.Preconditions;
import com.io7m.jlexing.core.LexicalPosition;
import com.io7m.jpra.model.Untyped;
Expand Down Expand Up @@ -91,9 +85,13 @@
import com.io7m.jranges.RangeInclusiveB;
import com.io7m.junreachable.UnimplementedCodeException;
import com.io7m.junreachable.UnreachableCodeException;
import io.vavr.collection.HashMap;
import io.vavr.collection.List;

import java.math.BigInteger;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -247,14 +245,14 @@ private TypeDeclPacked<IdentifierType, TType> checkTypeDeclPacked(
{
this.type_context = TypeExpressionContext.PACKED;

final ImmutableMap<FieldName, PackedFieldDeclValue<IdentifierType, Untyped>>
final io.vavr.collection.Map<FieldName, PackedFieldDeclValue<IdentifierType, Untyped>>
orig_named = t.getFieldsByName();
final MutableMap<FieldName, PackedFieldDeclValue<IdentifierType, TType>>
fields_named = Maps.mutable.empty();
final ImmutableList<PackedFieldDeclType<IdentifierType, Untyped>>
final java.util.HashMap<FieldName, PackedFieldDeclValue<IdentifierType, TType>>
fields_named = new java.util.HashMap<>();
final List<PackedFieldDeclType<IdentifierType, Untyped>>
orig_ordered = t.getFieldsInDeclarationOrder();
final MutableList<PackedFieldDeclType<IdentifierType, TType>>
fields_ordered = Lists.mutable.empty();
final ArrayList<PackedFieldDeclType<IdentifierType, TType>>
fields_ordered = new ArrayList<>();

final TPackedBuilderType b =
TPacked.newBuilder(this.package_ctx, t.getIdentifier(), t.getName());
Expand Down Expand Up @@ -295,11 +293,10 @@ public PackedFieldDeclType<IdentifierType, TType> matchValue(
Integer.valueOf(fields_named.size()),
Integer.valueOf(orig_named.size()));

fields_named.forEachKey(
k -> Preconditions.checkPreconditionV(
orig_named.containsKey(k),
"Names must contain %s",
k));
fields_named.forEach((k, value) -> {
Preconditions.checkPreconditionV(
orig_named.containsKey(k), "Names must contain %s", k);
});

final BigInteger sv = b.getCurrentSize().getValue();
if (!this.caps.isPackedSizeBitsSupported(sv)) {
Expand All @@ -320,26 +317,25 @@ public PackedFieldDeclType<IdentifierType, TType> matchValue(
Integer.valueOf(type.getFieldsByName().size()),
Integer.valueOf(orig_named.size()));

type.getFieldsByName().forEachKey(
k -> Preconditions.checkPreconditionV(
orig_named.containsKey(k),
"Names must contain %s",
k));
type.getFieldsByName().forEach((k, value) -> {
Preconditions.checkPreconditionV(
orig_named.containsKey(k), "Names must contain %s", k);
});

return new TypeDeclPacked<>(
t.getIdentifier(),
type,
fields_named.toImmutable(),
HashMap.ofAll(fields_named),
t.getName(),
fields_ordered.toImmutable());
List.ofAll(fields_ordered));
}

private PackedFieldDeclType<IdentifierType, TType>
checkTypeDeclPackedFieldValue(
final PackedFieldDeclValue<IdentifierType, Untyped> r,
final MutableList<PackedFieldDeclType<IdentifierType, TType>>
final ArrayList<PackedFieldDeclType<IdentifierType, TType>>
fields_ordered,
final MutableMap<FieldName, PackedFieldDeclValue<IdentifierType, TType>>
final java.util.HashMap<FieldName, PackedFieldDeclValue<IdentifierType, TType>>
fields_named,
final TPackedBuilderType b)
throws JPRACompilerCheckerException
Expand Down Expand Up @@ -372,7 +368,7 @@ private PackedFieldDeclValue<IdentifierType, TType> checkPackedFieldValue(
private PackedFieldDeclType<IdentifierType, TType>
checkTypeDeclPackedFieldPaddingBits(
final PackedFieldDeclPaddingBits<IdentifierType, Untyped> r,
final MutableList<PackedFieldDeclType<IdentifierType, TType>>
final ArrayList<PackedFieldDeclType<IdentifierType, TType>>
fields_ordered,
final TPackedBuilderType b)
throws JPRACompilerCheckerException
Expand Down Expand Up @@ -408,14 +404,14 @@ private TypeDeclRecord<IdentifierType, TType> checkTypeDeclRecord(
{
this.type_context = TypeExpressionContext.RECORD;

final ImmutableMap<FieldName, RecordFieldDeclValue<IdentifierType, Untyped>>
final io.vavr.collection.Map<FieldName, RecordFieldDeclValue<IdentifierType, Untyped>>
orig_named = t.getFieldsByName();
final MutableMap<FieldName, RecordFieldDeclValue<IdentifierType, TType>>
fields_named = Maps.mutable.empty();
final ImmutableList<RecordFieldDeclType<IdentifierType, Untyped>>
final java.util.HashMap<FieldName, RecordFieldDeclValue<IdentifierType, TType>>
fields_named = new java.util.HashMap<>();
final List<RecordFieldDeclType<IdentifierType, Untyped>>
orig_ordered = t.getFieldsInDeclarationOrder();
final MutableList<RecordFieldDeclType<IdentifierType, TType>>
fields_ordered = Lists.mutable.empty();
final ArrayList<RecordFieldDeclType<IdentifierType, TType>>
fields_ordered = new ArrayList<>();

final TRecordBuilderType b =
TRecord.newBuilder(this.package_ctx, t.getIdentifier(), t.getName());
Expand Down Expand Up @@ -454,9 +450,11 @@ public RecordFieldDeclType<IdentifierType, TType> matchValue(
fields_named.size() == orig_named.size(), "%d == %d",
Integer.valueOf(fields_named.size()),
Integer.valueOf(orig_named.size()));
fields_named.forEachKey(
k -> Preconditions.checkPreconditionV(
orig_named.containsKey(k), "Names must contain %s", k));

fields_named.forEach((k, value) -> {
Preconditions.checkPreconditionV(
orig_named.containsKey(k), "Names must contain %s", k);
});

final TRecord type = b.build();
Preconditions.checkPreconditionV(
Expand All @@ -469,24 +467,26 @@ public RecordFieldDeclType<IdentifierType, TType> matchValue(
"%d == %d",
Integer.valueOf(type.getFieldsByName().size()),
Integer.valueOf(orig_named.size()));
type.getFieldsByName().forEachKey(
k -> Preconditions.checkPreconditionV(
orig_named.containsKey(k), "Names must contain %s", k));

type.getFieldsByName().forEach((k, value) -> {
Preconditions.checkPreconditionV(
orig_named.containsKey(k), "Names must contain %s", k);
});

return new TypeDeclRecord<>(
t.getIdentifier(),
type,
fields_named.toImmutable(),
HashMap.ofAll(fields_named),
t.getName(),
fields_ordered.toImmutable());
List.ofAll(fields_ordered));
}

private RecordFieldDeclType<IdentifierType, TType>
checkTypeDeclRecordFieldValue(
final RecordFieldDeclValue<IdentifierType, Untyped> r,
final MutableList<RecordFieldDeclType<IdentifierType, TType>>
final ArrayList<RecordFieldDeclType<IdentifierType, TType>>
fields_ordered,
final MutableMap<FieldName, RecordFieldDeclValue<IdentifierType, TType>>
final java.util.HashMap<FieldName, RecordFieldDeclValue<IdentifierType, TType>>
fields_named,
final TRecordBuilderType b)
throws JPRACompilerCheckerException
Expand All @@ -504,7 +504,7 @@ public RecordFieldDeclType<IdentifierType, TType> matchValue(
private RecordFieldDeclType<IdentifierType, TType>
checkTypeDeclRecordFieldPaddingOctets(
final RecordFieldDeclPaddingOctets<IdentifierType, Untyped> r,
final MutableList<RecordFieldDeclType<IdentifierType, TType>>
final ArrayList<RecordFieldDeclType<IdentifierType, TType>>
fields_ordered,
final TRecordBuilderType b)
throws JPRACompilerCheckerException
Expand Down Expand Up @@ -1031,24 +1031,25 @@ private enum TypeExpressionContext
private static final class PackageContext implements PackageContextType
{
private final GlobalContextType context;
private final MutableMap<TypeName, TypeUserDefinedType> types;
private final java.util.HashMap<TypeName, TypeUserDefinedType> types;
private final PackageNameQualified name;
private final MutableMap<TypeName, TypeUserDefinedType> types_view;
private final Map<TypeName, TypeUserDefinedType> types_view;

PackageContext(
final GlobalContextType c,
final PackageNameQualified in_name)
{
this.context = Objects.requireNonNull(c, "Context");
this.types = Maps.mutable.empty();
this.types_view = this.types.asUnmodifiable();
this.types = new java.util.HashMap<>();
this.types_view = Collections.unmodifiableMap(this.types);
this.name = Objects.requireNonNull(in_name, "Name");
}

void putType(final TypeUserDefinedType t)
void putType(
final TypeUserDefinedType t)
{
Preconditions.checkPreconditionV(
!this.types.contains(t.getName()),
!this.types.containsKey(t.getName()),
"Types must not contain %s",
t.getName());
this.types.put(t.getName(), t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

package com.io7m.jpra.compiler.core.checker;

import com.gs.collections.api.list.ImmutableList;
import com.gs.collections.api.set.ImmutableSet;

import com.io7m.jranges.RangeInclusiveB;
import io.vavr.Tuple2;
import io.vavr.collection.List;
import io.vavr.collection.Set;

import java.math.BigInteger;

Expand All @@ -33,7 +34,7 @@ public interface JPRACheckerCapabilitiesType
* @return The set of supported {@code integer} sizes in records
*/

ImmutableList<RangeInclusiveB> getRecordIntegerSizeBitsSupported();
List<RangeInclusiveB> getRecordIntegerSizeBitsSupported();

/**
* @param size The size in bits
Expand Down Expand Up @@ -77,7 +78,7 @@ boolean isMatrixSizeElementsSupported(
* @return The set of supported {@code float} sizes in records
*/

ImmutableList<RangeInclusiveB> getRecordFloatSizeBitsSupported();
List<RangeInclusiveB> getRecordFloatSizeBitsSupported();

/**
* @param encoding The encoding
Expand All @@ -92,13 +93,13 @@ boolean isStringEncodingSupported(
* @return The set of supported string encodings
*/

ImmutableSet<String> getStringEncodingsSupported();
Set<String> getStringEncodingsSupported();

/**
* @return The set of supported vector sizes
*/

ImmutableList<RangeInclusiveB> getVectorSizeSupported();
List<RangeInclusiveB> getVectorSizeSupported();

/**
* @param size The size in bits
Expand All @@ -113,7 +114,7 @@ boolean isStringEncodingSupported(
* @return The set of supported {@code integer} sizes in vectors
*/

ImmutableList<RangeInclusiveB> getVectorIntegerSizeSupported();
List<RangeInclusiveB> getVectorIntegerSizeSupported();

/**
* @param size The size in bits
Expand All @@ -128,13 +129,13 @@ boolean isStringEncodingSupported(
* @return The set of supported {@code float} sizes in vectors
*/

ImmutableList<RangeInclusiveB> getVectorFloatSizeSupported();
List<RangeInclusiveB> getVectorFloatSizeSupported();

/**
* @return The set of supported matrix sizes
*/

ImmutableList<Tuple2<RangeInclusiveB, RangeInclusiveB>>
List<Tuple2<RangeInclusiveB, RangeInclusiveB>>
getMatrixSizeElementsSupported();

/**
Expand All @@ -150,7 +151,7 @@ boolean isStringEncodingSupported(
* @return The set of supported {@code integer} sizes in matrices
*/

ImmutableList<RangeInclusiveB> getMatrixIntegerSizeSupported();
List<RangeInclusiveB> getMatrixIntegerSizeSupported();

/**
* @param size The size in bits
Expand All @@ -165,13 +166,13 @@ boolean isStringEncodingSupported(
* @return The set of supported {@code float} sizes in matrices
*/

ImmutableList<RangeInclusiveB> getMatrixFloatSizeSupported();
List<RangeInclusiveB> getMatrixFloatSizeSupported();

/**
* @return The set of supported {@code integer} sizes in {@code packed} types
*/

ImmutableList<RangeInclusiveB> getPackedIntegerSizeBitsSupported();
List<RangeInclusiveB> getPackedIntegerSizeBitsSupported();

/**
* @param size The size in bits
Expand All @@ -186,7 +187,7 @@ boolean isStringEncodingSupported(
* @return The set of supported {@code packed} type sizes
*/

ImmutableList<RangeInclusiveB> getPackedSizeBitsSupported();
List<RangeInclusiveB> getPackedSizeBitsSupported();

/**
* @param size The size in bits
Expand Down
Loading

0 comments on commit 4e75bc5

Please sign in to comment.