Skip to content

Commit

Permalink
Reorganize standard library collections under cc (#18858)
Browse files Browse the repository at this point in the history
 1. Revert previous merge commit
2. Add all changes to capture tracking in the compiler to make (4) go
through.
3. Add all collection classes without changes to test directory in one
commit
[3caf116](3caf116).
4. Add all changes to collection classes made for capture checking in
another commit
[b5bfbab](b5bfbab).
  • Loading branch information
odersky authored Nov 14, 2023
2 parents 0cd94fc + b5bfbab commit 49587e2
Show file tree
Hide file tree
Showing 27 changed files with 4,727 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/pos-special/stdlib/collection/concurrent/BasicNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.collection.concurrent;

public abstract class BasicNode {

public abstract String string(int lev);

}
37 changes: 37 additions & 0 deletions tests/pos-special/stdlib/collection/concurrent/CNodeBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.collection.concurrent;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

abstract class CNodeBase<K, V> extends MainNode<K, V> {

@SuppressWarnings("unchecked")
public static final AtomicIntegerFieldUpdater<CNodeBase<?, ?>> updater =
AtomicIntegerFieldUpdater.newUpdater((Class<CNodeBase<?, ?>>) (Class<?>) CNodeBase.class, "csize");

public volatile int csize = -1;

public boolean CAS_SIZE(int oldval, int nval) {
return updater.compareAndSet(this, oldval, nval);
}

public void WRITE_SIZE(int nval) {
updater.set(this, nval);
}

public int READ_SIZE() {
return updater.get(this);
}

}
15 changes: 15 additions & 0 deletions tests/pos-special/stdlib/collection/concurrent/Gen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.collection.concurrent;

final class Gen {}
39 changes: 39 additions & 0 deletions tests/pos-special/stdlib/collection/concurrent/INodeBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.collection.concurrent;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

abstract class INodeBase<K, V> extends BasicNode {

@SuppressWarnings("unchecked")
public static final AtomicReferenceFieldUpdater<INodeBase<?, ?>, MainNode<?, ?>> updater =
AtomicReferenceFieldUpdater.newUpdater((Class<INodeBase<?, ?>>) (Class<?>) INodeBase.class, (Class<MainNode<?, ?>>) (Class<?>) MainNode.class, "mainnode");

static final Object RESTART = new Object();

static final Object NO_SUCH_ELEMENT_SENTINEL = new Object();

public volatile MainNode<K, V> mainnode = null;

public final Gen gen;

public INodeBase(Gen generation) {
gen = generation;
}

public BasicNode prev() {
return null;
}

}
46 changes: 46 additions & 0 deletions tests/pos-special/stdlib/collection/concurrent/MainNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.collection.concurrent;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

abstract class MainNode<K, V> extends BasicNode {

@SuppressWarnings("unchecked")
public static final AtomicReferenceFieldUpdater<MainNode<?, ?>, MainNode<?, ?>> updater =
AtomicReferenceFieldUpdater.newUpdater((Class<MainNode<?, ?>>) (Class<?>) MainNode.class, (Class<MainNode<?, ?>>) (Class<?>) MainNode.class, "prev");

public volatile MainNode<K, V> prev = null;

public abstract int cachedSize(Object ct);

// standard contract
public abstract int knownSize();

public boolean CAS_PREV(MainNode<K, V> oldval, MainNode<K, V> nval) {
return updater.compareAndSet(this, oldval, nval);
}

public void WRITE_PREV(MainNode<K, V> nval) {
updater.set(this, nval);
}

// do we need this? unclear in the javadocs...
// apparently not - volatile reads are supposed to be safe
// regardless of whether there are concurrent ARFU updates
@Deprecated @SuppressWarnings("unchecked")
public MainNode<K, V> READ_PREV() {
return (MainNode<K, V>) updater.get(this);
}

}
Loading

0 comments on commit 49587e2

Please sign in to comment.